mirror of
https://github.com/musix-org/musix-oss
synced 2024-11-10 08:10:18 +00:00
34 lines
1.3 KiB
JavaScript
34 lines
1.3 KiB
JavaScript
module.exports = {
|
|
name: 'voiceStateUpdate',
|
|
async execute(client, oldState, newState) {
|
|
let change = false;
|
|
const queue = client.queue.get(newState.guild.id);
|
|
if (!queue) return;
|
|
if (newState.member.id === client.user.id && oldState.member.id === client.user.id) {
|
|
if (newState.member.voice.channel === null) {
|
|
queue.songs = [];
|
|
queue.looping = false;
|
|
queue.endReason = "manual disconnect";
|
|
return client.queue.delete(newState.guild.id);
|
|
}
|
|
if (newState.member.voice.channel !== queue.voiceChannel) {
|
|
change = true;
|
|
queue.voiceChannel = newState.member.voice.channel;
|
|
queue.connection = newState.connection;
|
|
}
|
|
}
|
|
if (oldState.channel === null) return;
|
|
if (oldState.channel.members.size === 1 && oldState.channel === queue.voiceChannel || change) {
|
|
setTimeout(() => {
|
|
if (!queue) return;
|
|
if (queue.voiceChannel.members.size === 1) {
|
|
queue.songs = [];
|
|
queue.looping = false;
|
|
queue.endReason = "Timeout";
|
|
queue.connection.dispatcher.end();
|
|
}
|
|
}, 120000);
|
|
}
|
|
}
|
|
}
|