eximiabots-radiox/src/client/events/voiceStateUpdate.js

57 lines
2.5 KiB
JavaScript
Raw Normal View History

2020-03-02 19:38:42 +00:00
module.exports = {
name: "voiceStateUpdate",
async execute(client, oldState, newState) {
if (oldState.channel === null) return;
let change = false;
const radio = client.radio.get(newState.guild.id);
if (!radio) return;
2020-03-11 13:21:15 +00:00
if (newState.member.id === client.user.id && oldState.member.id === client.user.id) {
if (newState.channel === null) {
client.funcs.statisticsUpdate(client, newState.guild, radio);
return client.radio.delete(newState.guild.id);
}
const newPermissions = newState.channel.permissionsFor(newState.client.user);
if (!newPermissions.has("CONNECT") || !newPermissions.has("SPEAK") || !newPermissions.has("VIEW_CHANNEL")) {
try {
setTimeout(
2021-08-04 11:34:41 +00:00
async () => (
radio.connection = await joinVoiceChannel({
channelId: oldState.channel.id,
guildId: oldState.channel.guild.id,
adapterCreator: createDiscordJSAdapter(oldState.channel)
})
//radio.connection = await oldState.channel.join()
),
1000
);
} catch (error) {
client.funcs.statisticsUpdate(client, newState.guild, radio);
2021-08-04 10:52:30 +00:00
radio.connection.destroy();
radio.audioPlayer.stop();
client.radio.delete(oldState.guild.id);
}
return;
}
if (newState.channel !== radio.voiceChannel) {
change = true;
radio.voiceChannel = newState.channel;
2021-08-04 11:40:06 +00:00
radio.connection = getVoiceConnection(voiceChannel.guild.id);
2021-08-04 11:34:41 +00:00
//radio.connection = await newState.channel.join();
}
}
if ((oldState.channel.members.size === 1 && oldState.channel === radio.voiceChannel) || change) {
setTimeout(() => {
if (!radio || !radio.connection.dispatcher || !radio.connection.dispatcher === null) return;
if (radio.voiceChannel.members.size === 1) {
client.funcs.statisticsUpdate(client, newState.guild, radio);
2021-08-04 10:52:30 +00:00
radio.connection.destroy();
radio.audioPlayer.stop();
client.radio.delete(newState.guild.id);
}
}, 120000);
2020-03-02 19:38:42 +00:00
}
},
2020-08-03 10:02:52 +00:00
};