mirror of
https://github.com/warengroup/eximiabots-radiox.git
synced 2024-11-09 23:40:18 +00:00
Update voiceStateUpdate.js
This commit is contained in:
parent
abbc996524
commit
716786e296
@ -1,22 +1,38 @@
|
||||
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;
|
||||
if (newState.member.id === client.user.id && oldState.member.id === client.user.id) {
|
||||
if (newState.member.voice.channel === null) {
|
||||
if (newState.channel === null) {
|
||||
radio.songs = [];
|
||||
radio.looping = false;
|
||||
return client.radio.delete(newState.guild.id);
|
||||
}
|
||||
if (newState.member.voice.channel !== radio.voiceChannel) {
|
||||
|
||||
if (newState.channel !== radio.voiceChannel) {
|
||||
change = true;
|
||||
radio.voiceChannel = newState.member.voice.channel;
|
||||
radio.voiceChannel = newState.channel;
|
||||
radio.connection = newState.connection;
|
||||
}
|
||||
const newPermissions = newState.channel.permissionsFor(newState.client.user);
|
||||
if (!newPermissions.has('CONNECT') || !newPermissions.has('SPEAK') || !newPermissions.has('VIEW_CHANNEL')) {
|
||||
try {
|
||||
const connection = await oldState.channel.join();
|
||||
radio.connection = connection;
|
||||
} catch (error) {
|
||||
radio.songs = [];
|
||||
radio.looping = false;
|
||||
radio.connection.dispatcher.destroy();
|
||||
radio.voiceChannel.leave();
|
||||
client.radio.delete(msg.guild.id);
|
||||
client.debug_channel.send("Error with connecting to voice channel: " + error);
|
||||
return msg.channel.send(`<:redx:674263474704220182> An error occured: ${error}`);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (oldState.channel === null) return;
|
||||
if (oldState.channel.members.size === 1 && oldState.channel === radio.voiceChannel || change) {
|
||||
setTimeout(() => {
|
||||
if (!radio) return;
|
||||
|
Loading…
Reference in New Issue
Block a user