diff --git a/commands/stop.js b/commands/stop.js index d82baed..0259dc0 100644 --- a/commands/stop.js +++ b/commands/stop.js @@ -24,11 +24,13 @@ exports.run = async (client, message) => { if (guild.queue.length < 1 || !guild.playing || !guild.dispatcher) return message.channel.send('Nothing is playing.') if (!message.member.voice.channel) return message.channel.send('You need to be in voice channel to use this command!') + guild.dispatcher.end('silent') + + guild.queue = [] guild.playing = false guild.paused = false - guild.queue = [] - - guild.dispatcher.end('silent') + guild.dispatcher = null + guild.skippers = [] message.channel.send('Playback stopped!') } diff --git a/events/voiceStateUpdate.js b/events/voiceStateUpdate.js index f2e0caf..9850f01 100644 --- a/events/voiceStateUpdate.js +++ b/events/voiceStateUpdate.js @@ -7,33 +7,32 @@ module.exports = (client, oldState, newState) => { const guild = music.getGuild(newState.guild.id) if (guild.playing && guild.voiceChannel.id === oldState.channelID) { - if (guild.voiceChannel.members.size === 1) { + if (guild.voiceChannel.members.filter(member => !member.user.bot).size < 1) { guild.autoDisconnect = true - setTimeout(() => { - if (guild.voiceChannel.members.size === 1 && guild.autoDisconnect) { - setTimeout(() => { - if (guild.voiceChannel.members.size === 1 && guild.autoDisconnect) { - setTimeout(() => { - if (guild.voiceChannel.members.size === 1 && guild.autoDisconnect) { - guild.playing = false - guild.queue = [] + guild.message.channel.send(`The music will end in 2 minutes if nobody rejoins **${guild.voiceChannel.name}**`) + .then(msg => { + msg.delete({ timeout: 120000 }) + }) - // Probably should be async? But no need here I think - guild.dispatcher.end('silent') - guild.message.channel.send('No one is listening to me. Leaving voice chat!') - } else { - guild.autoDisconnect = false - } - }, 30000) - } else { - guild.autoDisconnect = false - } - }, 20000) + setTimeout(() => { + if (guild.dispatcher !== null && guild.voiceChannel.members.filter(member => !member.user.bot).size < 1 && guild.autoDisconnect) { + // Probably should be async? But no need here I think + guild.dispatcher.end('silent') + + guild.queue = [] + guild.playing = false + guild.paused = false + guild.dispatcher = null + guild.skippers = [] + + guild.message.channel.send('The music has ended because no one was listening to me ;~;') } else { guild.autoDisconnect = false } - }, 10000) + }, 120000) + } else { + guild.autoDisconnect = false } } } diff --git a/utils/music.js b/utils/music.js index 38887c6..d08be5d 100644 --- a/utils/music.js +++ b/utils/music.js @@ -93,8 +93,11 @@ exports.play = async function (client, message, query, ignoreQueue) { // Fix the bot if somehow broken // music "playing", nothing in queue if ((guild.playing || guild.dispatcher) && guild.queue.length === 0) { + guild.queue = [] guild.playing = false + guild.paused = false guild.dispatcher = null + guild.skippers = [] // music not playing, something is in queue } else if (!guild.playing && !guild.dispatcher && guild.queue.length > 0) { guild.queue = [] @@ -188,7 +191,11 @@ exports.play = async function (client, message, query, ignoreQueue) { if (guild.queue.length > 0) { exports.play(client, message, null, true) } else { + guild.queue = [] + guild.playing = false + guild.paused = false guild.dispatcher = null + guild.skippers = [] connection.disconnect() }