1
0
mirror of https://github.com/musix-org/musix-oss synced 2024-09-20 07:41:56 +00:00
musix-oss/events/clientEvents/voiceStateUpdate.js
2020-03-19 16:45:05 +02:00

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);
}
}
}