From dc35e730a796902d29b48fc86518958577b1a939 Mon Sep 17 00:00:00 2001 From: MatteZ02 <47610069+MatteZ02@users.noreply.github.com> Date: Wed, 4 Mar 2020 23:17:45 +0200 Subject: [PATCH] auto leave --- events/voiceStateUpdate.js | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/events/voiceStateUpdate.js b/events/voiceStateUpdate.js index f8631d20..9f07f83f 100644 --- a/events/voiceStateUpdate.js +++ b/events/voiceStateUpdate.js @@ -1,20 +1,40 @@ module.exports = { name: 'voiceStateUpdate', async execute(client, oldState, newState) { + let change = false; const serverQueue = client.queue.get(newState.guild.id); if (!serverQueue) return; + console.log('vocestate') if (newState.member.id === client.user.id && oldState.member.id === client.user.id) { + console.log('cocecece') if (newState.member.voice.channel === null) { + console.log('discoennect') serverQueue.songs = []; serverQueue.looping = false; serverQueue.endReason = "manual disconnect"; return client.queue.delete(newState.guild.id); } if (newState.member.voice.channel !== serverQueue.voiceChannel) { + console.log('wrong channe') + change = true; serverQueue.voiceChannel = newState.member.voice.channel; serverQueue.connection = newState.connection; - return; } } + if (oldState.channel === null) return; + if (oldState.channel.members.size === 1 && oldState.channel === serverQueue.voiceChannel || change) { + console.log('left alone') + setTimeout(() => { + console.log('timeout') + if (!serverQueue) return; + if (serverQueue.voiceChannel.members.size === 1) { + console.log('still alone') + serverQueue.songs = []; + serverQueue.looping = false; + serverQueue.endReason = "Timeout"; + serverQueue.connection.dispatcher.end(); + } + }, 12000); + } } }