diff --git a/commands/play.js b/commands/play.js index 727e5ea..aba6c56 100644 --- a/commands/play.js +++ b/commands/play.js @@ -173,6 +173,12 @@ module.exports = { } const info = JSON.parse(stdout); + + if (!info.entries || info.entries.length === 0) { + message.reply('No results found for your search.'); + return; + } + const url = info.entries[0].webpage_url; title = info.entries[0].title; @@ -223,4 +229,4 @@ function isValidURL(string) { } catch (_) { return false; } -} +} \ No newline at end of file diff --git a/utils/queueManager.js b/utils/queueManager.js index 417eea9..ba5d27e 100644 --- a/utils/queueManager.js +++ b/utils/queueManager.js @@ -1,4 +1,4 @@ -const { createAudioPlayer, createAudioResource, AudioPlayerStatus, joinVoiceChannel } = require('@discordjs/voice'); +const { createAudioPlayer, createAudioResource, AudioPlayerStatus, joinVoiceChannel, VoiceConnectionStatus } = require('@discordjs/voice'); const fs = require('fs'); const queueMap = new Map(); @@ -88,12 +88,25 @@ function playNextInQueue(guildId) { } function playTrack(guildId, voiceChannel, track) { - const connection = joinVoiceChannel({ + let connection = joinVoiceChannel({ channelId: voiceChannel.id, guildId: guildId, adapterCreator: voiceChannel.guild.voiceAdapterCreator, }); + connection.on(VoiceConnectionStatus.Disconnected, async (oldState, newState) => { + try { + await Promise.race([ + entersState(connection, VoiceConnectionStatus.Signalling, 5_000), + entersState(connection, VoiceConnectionStatus.Connecting, 5_000), + ]); + } catch (error) { + connection.destroy(); + currentTrackMap.delete(guildId); + queueMap.delete(guildId); + } + }); + const audioPlayer = playerMap.get(guildId) || createAudioPlayer(); playerMap.set(guildId, audioPlayer);