1
0
mirror of https://github.com/musix-org/musix-oss synced 2024-11-10 08:10:18 +00:00
musix-oss/events/voiceStateUpdate.js

34 lines
1.4 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-04 20:29:12 +00:00
const serverQueue = client.queue.get(newState.guild.id);
2020-02-05 20:02:53 +00:00
if (!serverQueue) 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) {
serverQueue.songs = [];
serverQueue.looping = false;
serverQueue.endReason = "manual disconnect";
return client.queue.delete(newState.guild.id);
}
if (newState.member.voice.channel !== serverQueue.voiceChannel) {
2020-03-04 21:17:45 +00:00
change = true;
2020-03-04 20:29:12 +00:00
serverQueue.voiceChannel = newState.member.voice.channel;
serverQueue.connection = newState.connection;
2020-02-05 20:02:53 +00:00
}
}
2020-03-04 21:17:45 +00:00
if (oldState.channel === null) return;
if (oldState.channel.members.size === 1 && oldState.channel === serverQueue.voiceChannel || change) {
setTimeout(() => {
if (!serverQueue) return;
if (serverQueue.voiceChannel.members.size === 1) {
serverQueue.songs = [];
serverQueue.looping = false;
serverQueue.endReason = "Timeout";
serverQueue.connection.dispatcher.end();
}
}, 12000);
}
2020-02-05 20:02:53 +00:00
}
}