mirror of
https://github.com/musix-org/musix-oss
synced 2024-11-10 05:10:17 +00:00
auto leave
This commit is contained in:
parent
7637cb3e84
commit
dc35e730a7
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user