summaryrefslogtreecommitdiff
path: root/src/utils
diff options
context:
space:
mode:
Diffstat (limited to 'src/utils')
-rw-r--r--src/utils/helpers.js28
-rw-r--r--src/utils/player.js8
2 files changed, 29 insertions, 7 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 = {
diff --git a/src/utils/player.js b/src/utils/player.js
index 7085dae..c17ba56 100644
--- a/src/utils/player.js
+++ b/src/utils/player.js
@@ -100,7 +100,7 @@ async function preloadSong(song) {
}
async function getVideoInfo(query) {
- return new Promise((resolve, reject) => {
+ return new Promise((resolve) => {
const isUrl = query.startsWith('http://') || query.startsWith('https://');
const isPlaylist = isUrl && query.includes('list=');
@@ -153,7 +153,7 @@ async function getVideoInfo(query) {
duration: info.duration || 0,
thumbnail: info.thumbnail || info.thumbnails?.[0]?.url,
};
- } catch (e) {
+ } catch (_e) {
return null;
}
}).filter(v => v !== null);
@@ -221,7 +221,7 @@ function setupFFmpegMonitoring(ffmpeg, song, guildId, queue, seekSeconds, onRetr
processesKilled = true;
try {
ffmpeg.kill('SIGKILL');
- } catch (e) {}
+ } catch (_e) {}
}
};
@@ -497,7 +497,7 @@ function getCurrentProgress(queue) {
return null;
}
- let elapsed = 0;
+ let elapsed;
if (queue.resource && queue.resource.playbackDuration !== undefined) {
elapsed = Math.floor(queue.resource.playbackDuration / 1000) + (queue.seekOffset || 0);