diff --git a/events/voiceStateUpdate.js b/events/voiceStateUpdate.js index 2da2b3f..bf07ff0 100644 --- a/events/voiceStateUpdate.js +++ b/events/voiceStateUpdate.js @@ -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;