1
0
mirror of https://github.com/musix-org/musix-oss synced 2024-12-23 16:13:18 +00:00
musix-oss/events/clientEvents/voiceStateUpdate.js

34 lines
1.3 KiB
JavaScript
Raw Normal View History

2020-02-05 20:02:53 +00:00
module.exports = {
name: 'voiceStateUpdate',
2020-03-04 20:29:12 +00:00
async execute(client, oldState, newState) {
2020-03-04 21:17:45 +00:00
let change = false;
2020-03-14 16:38:02 +00:00
const queue = client.queue.get(newState.guild.id);
if (!queue) return;
2020-03-04 20:29:12 +00:00
if (newState.member.id === client.user.id && oldState.member.id === client.user.id) {
if (newState.member.voice.channel === null) {
2020-03-14 16:38:02 +00:00
queue.songs = [];
queue.looping = false;
queue.endReason = "manual disconnect";
2020-03-04 20:29:12 +00:00
return client.queue.delete(newState.guild.id);
}
2020-03-14 16:38:02 +00:00
if (newState.member.voice.channel !== queue.voiceChannel) {
2020-03-04 21:17:45 +00:00
change = true;
2020-03-14 16:38:02 +00:00
queue.voiceChannel = newState.member.voice.channel;
queue.connection = newState.connection;
2020-02-05 20:02:53 +00:00
}
}
2020-03-04 21:17:45 +00:00
if (oldState.channel === null) return;
2020-03-14 16:38:02 +00:00
if (oldState.channel.members.size === 1 && oldState.channel === queue.voiceChannel || change) {
2020-03-04 21:17:45 +00:00
setTimeout(() => {
2020-03-14 16:38:02 +00:00
if (!queue) return;
if (queue.voiceChannel.members.size === 1) {
queue.songs = [];
queue.looping = false;
queue.endReason = "Timeout";
queue.connection.dispatcher.end();
2020-03-04 21:17:45 +00:00
}
2020-03-15 19:52:39 +00:00
}, 120000);
2020-03-04 21:17:45 +00:00
}
2020-02-05 20:02:53 +00:00
}
}