eximiabots-radiox/events/voiceStateUpdate.js

33 lines
1.3 KiB
JavaScript
Raw Normal View History

2020-03-02 19:38:42 +00:00
module.exports = {
name: 'voiceStateUpdate',
2020-03-07 20:07:54 +00:00
async execute(client, oldState, newState) {
let change = false;
const radio = client.radio.get(newState.guild.id);
if (!radio) return;
if (newState.member.id === client.user.id && oldState.member.id === client.user.id) {
if (newState.member.voice.channel === null) {
radio.songs = [];
radio.looping = false;
2020-03-08 14:19:24 +00:00
return client.radio.delete(newState.guild.id);
2020-03-02 19:38:42 +00:00
}
2020-03-07 20:07:54 +00:00
if (newState.member.voice.channel !== radio.voiceChannel) {
change = true;
radio.voiceChannel = newState.member.voice.channel;
radio.connection = newState.connection;
}
}
if (oldState.channel === null) return;
if (oldState.channel.members.size === 1 && oldState.channel === radio.voiceChannel || change) {
setTimeout(() => {
if (!radio) return;
if (radio.voiceChannel.members.size === 1) {
radio.songs = [];
radio.looping = false;
2020-03-08 19:20:47 +00:00
radio.connection.dispatcher.destroy();
2020-03-11 11:41:25 +00:00
radio.voiceChannel.leave();
client.radio.delete(newState.guild.id);
2020-03-07 20:07:54 +00:00
}
2020-03-11 11:42:01 +00:00
}, 120000);
2020-03-02 19:38:42 +00:00
}
}
2020-03-08 19:20:47 +00:00
}