diff options
Diffstat (limited to 'src/utils/helpers.js')
| -rw-r--r-- | src/utils/helpers.js | 28 |
1 files changed, 25 insertions, 3 deletions
diff --git a/src/utils/helpers.js b/src/utils/helpers.js index f18408f..0362528 100644 --- a/src/utils/helpers.js +++ b/src/utils/helpers.js @@ -1,3 +1,5 @@ +const { PermissionsBitField } = require('discord.js'); + function getQueueOrReply(interaction, queues, message = 'Not in a voice channel!') { const queue = queues.get(interaction.guild.id); @@ -10,12 +12,32 @@ function getQueueOrReply(interaction, queues, message = 'Not in a voice channel! } function requireVoiceChannel(interaction) { - if (!interaction.member?.voice?.channel) { + const voiceChannel = interaction.member?.voice?.channel; + + if (!voiceChannel) { interaction.editReply('You need to be in a voice channel!'); return null; } - - return interaction.member.voice.channel; + + const botMember = interaction.guild?.members?.me; + if (!botMember) { + interaction.editReply('Could not validate bot permissions in your voice channel. Try again in a moment.'); + return null; + } + + const perms = voiceChannel.permissionsFor(botMember); + const missing = []; + + if (!perms?.has(PermissionsBitField.Flags.ViewChannel)) missing.push('View Channel'); + if (!perms?.has(PermissionsBitField.Flags.Connect)) missing.push('Connect'); + if (!perms?.has(PermissionsBitField.Flags.Speak)) missing.push('Speak'); + + if (missing.length > 0) { + interaction.editReply(`I am missing permissions in that voice channel: ${missing.join(', ')}`); + return null; + } + + return voiceChannel; } module.exports = { |
