summaryrefslogtreecommitdiff
path: root/src/utils/helpers.js
diff options
context:
space:
mode:
authorYour Name <you@example.com>2026-03-21 01:41:17 +0100
committerYour Name <you@example.com>2026-03-21 01:41:17 +0100
commit768b537946da0abd89949648b803d625542c8a7d (patch)
tree6fbce39026bf008d3c05fc58cfd0b97cc84ab7e4 /src/utils/helpers.js
parent09e546c4a7e1bf69784be5e8fe1200a7d5a8c955 (diff)
qol cedaHEADmaster
Diffstat (limited to 'src/utils/helpers.js')
-rw-r--r--src/utils/helpers.js28
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 = {