mirror of
https://github.com/darksaid98/cadence-discord-bot.git
synced 2026-12-03 14:38:49 +00:00
fix: Also validate is user is in same voice channel as bot for commands
This commit is contained in:
1 parent
f59055807f
commit
311e141992
14 files changed
+94
-17
No files matched your search
@@ -1,6 +1,6 @@
|
||||
const logger = require('../../services/logger');
|
||||
const { embedOptions, ffmpegFilterOptions } = require('../../config');
|
||||
const { notInVoiceChannel } = require('../../utils/validation/voiceChannelValidator');
|
||||
const { notInVoiceChannel, notInSameVoiceChannel } = require('../../utils/validation/voiceChannelValidator');
|
||||
const { queueDoesNotExist, queueNoCurrentTrack } = require('../../utils/validation/queueValidator');
|
||||
const {
|
||||
SlashCommandBuilder,
|
||||
@@ -31,6 +31,10 @@ module.exports = {
|
||||
return;
|
||||
}
|
||||
|
||||
if (await notInSameVoiceChannel(interaction, queue)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (await queueNoCurrentTrack(interaction, queue)) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
const logger = require('../../services/logger');
|
||||
const { embedOptions } = require('../../config');
|
||||
const { notInVoiceChannel } = require('../../utils/validation/voiceChannelValidator');
|
||||
const { notInVoiceChannel, notInSameVoiceChannel } = require('../../utils/validation/voiceChannelValidator');
|
||||
const { SlashCommandBuilder, EmbedBuilder } = require('discord.js');
|
||||
const { useQueue } = require('discord-player');
|
||||
|
||||
@@ -34,6 +34,10 @@ module.exports = {
|
||||
});
|
||||
}
|
||||
|
||||
if (await notInSameVoiceChannel(interaction, queue)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!queue.deleted) {
|
||||
queue.delete();
|
||||
logger.debug(
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
const logger = require('../../services/logger');
|
||||
const { embedOptions, botOptions } = require('../../config');
|
||||
const { notInVoiceChannel } = require('../../utils/validation/voiceChannelValidator');
|
||||
const { notInVoiceChannel, notInSameVoiceChannel } = require('../../utils/validation/voiceChannelValidator');
|
||||
const { queueDoesNotExist } = require('../../utils/validation/queueValidator');
|
||||
const { SlashCommandBuilder, EmbedBuilder } = require('discord.js');
|
||||
const { useQueue } = require('discord-player');
|
||||
@@ -36,6 +36,10 @@ module.exports = {
|
||||
return;
|
||||
}
|
||||
|
||||
if (await notInSameVoiceChannel(interaction, queue)) {
|
||||
return;
|
||||
}
|
||||
|
||||
const loopModesFormatted = new Map([
|
||||
[0, 'disabled'],
|
||||
[1, 'track'],
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
const logger = require('../../services/logger');
|
||||
const { embedOptions, playerOptions } = require('../../config');
|
||||
const { notInVoiceChannel } = require('../../utils/validation/voiceChannelValidator');
|
||||
const { notInVoiceChannel, notInSameVoiceChannel } = require('../../utils/validation/voiceChannelValidator');
|
||||
const { queueDoesNotExist, queueNoCurrentTrack } = require('../../utils/validation/queueValidator');
|
||||
const { SlashCommandBuilder, EmbedBuilder, ActionRowBuilder, ButtonBuilder } = require('discord.js');
|
||||
const { useQueue } = require('discord-player');
|
||||
@@ -24,6 +24,10 @@ module.exports = {
|
||||
return;
|
||||
}
|
||||
|
||||
if (await notInSameVoiceChannel(interaction, queue)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (await queueNoCurrentTrack(interaction, queue)) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
const logger = require('../../services/logger');
|
||||
const { embedOptions } = require('../../config');
|
||||
const { notInVoiceChannel } = require('../../utils/validation/voiceChannelValidator');
|
||||
const { notInVoiceChannel, notInSameVoiceChannel } = require('../../utils/validation/voiceChannelValidator');
|
||||
const { queueDoesNotExist, queueNoCurrentTrack } = require('../../utils/validation/queueValidator');
|
||||
const { SlashCommandBuilder, EmbedBuilder } = require('discord.js');
|
||||
const { useQueue } = require('discord-player');
|
||||
@@ -24,6 +24,10 @@ module.exports = {
|
||||
return;
|
||||
}
|
||||
|
||||
if (await notInSameVoiceChannel(interaction, queue)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (await queueNoCurrentTrack(interaction, queue)) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
const logger = require('../../services/logger');
|
||||
const { embedOptions, playerOptions, botOptions } = require('../../config');
|
||||
const { notInVoiceChannel } = require('../../utils/validation/voiceChannelValidator');
|
||||
const { notInVoiceChannel, notInSameVoiceChannel } = require('../../utils/validation/voiceChannelValidator');
|
||||
const { cannotJoinVoiceOrTalk } = require('../../utils/validation/permissionValidator');
|
||||
const { transformQuery } = require('../../utils/validation/searchQueryValidator');
|
||||
const { SlashCommandBuilder, EmbedBuilder } = require('discord.js');
|
||||
@@ -48,8 +48,8 @@ module.exports = {
|
||||
|
||||
return interaction.respond(response);
|
||||
},
|
||||
execute: async ({ interaction }) => {
|
||||
if (await notInVoiceChannel(interaction)) {
|
||||
execute: async ({ interaction, client }) => {
|
||||
if (await notInVoiceChannel(interaction, client)) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -57,6 +57,11 @@ module.exports = {
|
||||
return;
|
||||
}
|
||||
|
||||
let queue = useQueue(interaction.guild.id);
|
||||
if (queue && (await notInSameVoiceChannel(interaction, queue))) {
|
||||
return;
|
||||
}
|
||||
|
||||
const player = useMainPlayer();
|
||||
const query = interaction.options.getString('query');
|
||||
|
||||
@@ -107,7 +112,7 @@ module.exports = {
|
||||
});
|
||||
}
|
||||
|
||||
let queue = useQueue(interaction.guild.id);
|
||||
queue = useQueue(interaction.guild.id);
|
||||
let queueSize = queue?.size ?? 0;
|
||||
|
||||
if ((searchResult.playlist && searchResult.tracks.length) > playerOptions.maxQueueSize - queueSize) {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
const logger = require('../../services/logger');
|
||||
const { embedOptions, playerOptions } = require('../../config');
|
||||
const { notInVoiceChannel } = require('../../utils/validation/voiceChannelValidator');
|
||||
const { notInVoiceChannel, notInSameVoiceChannel } = require('../../utils/validation/voiceChannelValidator');
|
||||
const { SlashCommandBuilder, EmbedBuilder } = require('discord.js');
|
||||
const { useQueue } = require('discord-player');
|
||||
|
||||
@@ -19,6 +19,11 @@ module.exports = {
|
||||
}
|
||||
|
||||
const queue = useQueue(interaction.guild.id);
|
||||
|
||||
if (await notInSameVoiceChannel(interaction, queue)) {
|
||||
return;
|
||||
}
|
||||
|
||||
const pageIndex = (interaction.options.getNumber('page') || 1) - 1;
|
||||
let queueString = '';
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
const logger = require('../../services/logger');
|
||||
const { embedOptions } = require('../../config');
|
||||
const { notInVoiceChannel } = require('../../utils/validation/voiceChannelValidator');
|
||||
const { notInVoiceChannel, notInSameVoiceChannel } = require('../../utils/validation/voiceChannelValidator');
|
||||
const { queueDoesNotExist } = require('../../utils/validation/queueValidator');
|
||||
const { SlashCommandBuilder, EmbedBuilder } = require('discord.js');
|
||||
const { useQueue } = require('discord-player');
|
||||
@@ -31,6 +31,10 @@ module.exports = {
|
||||
return;
|
||||
}
|
||||
|
||||
if (await notInSameVoiceChannel(interaction, queue)) {
|
||||
return;
|
||||
}
|
||||
|
||||
const removeTrackNumber = interaction.options.getNumber('tracknumber');
|
||||
|
||||
if (removeTrackNumber > queue.tracks.data.length) {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
const logger = require('../../services/logger');
|
||||
const { embedOptions } = require('../../config');
|
||||
const { notInVoiceChannel } = require('../../utils/validation/voiceChannelValidator');
|
||||
const { notInVoiceChannel, notInSameVoiceChannel } = require('../../utils/validation/voiceChannelValidator');
|
||||
const { queueDoesNotExist, queueNoCurrentTrack } = require('../../utils/validation/queueValidator');
|
||||
const { SlashCommandBuilder, EmbedBuilder } = require('discord.js');
|
||||
const { useQueue } = require('discord-player');
|
||||
@@ -30,6 +30,10 @@ module.exports = {
|
||||
return;
|
||||
}
|
||||
|
||||
if (await notInSameVoiceChannel(interaction, queue)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (await queueNoCurrentTrack(interaction, queue)) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
const logger = require('../../services/logger');
|
||||
const { embedOptions } = require('../../config');
|
||||
const { notInVoiceChannel } = require('../../utils/validation/voiceChannelValidator');
|
||||
const { notInVoiceChannel, notInSameVoiceChannel } = require('../../utils/validation/voiceChannelValidator');
|
||||
const { queueDoesNotExist, queueIsEmpty } = require('../../utils/validation/queueValidator');
|
||||
const { SlashCommandBuilder, EmbedBuilder } = require('discord.js');
|
||||
const { useQueue } = require('discord-player');
|
||||
@@ -24,6 +24,10 @@ module.exports = {
|
||||
return;
|
||||
}
|
||||
|
||||
if (await notInSameVoiceChannel(interaction, queue)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (await queueIsEmpty(interaction, queue)) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
const logger = require('../../services/logger');
|
||||
const { embedOptions } = require('../../config');
|
||||
const { notInVoiceChannel } = require('../../utils/validation/voiceChannelValidator');
|
||||
const { notInVoiceChannel, notInSameVoiceChannel } = require('../../utils/validation/voiceChannelValidator');
|
||||
const { queueDoesNotExist, queueNoCurrentTrack } = require('../../utils/validation/queueValidator');
|
||||
const { SlashCommandBuilder, EmbedBuilder } = require('discord.js');
|
||||
const { useQueue } = require('discord-player');
|
||||
@@ -27,6 +27,10 @@ module.exports = {
|
||||
return;
|
||||
}
|
||||
|
||||
if (await notInSameVoiceChannel(interaction, queue)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (await queueNoCurrentTrack(interaction, queue)) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
const logger = require('../../services/logger');
|
||||
const { embedOptions } = require('../../config');
|
||||
const { notInVoiceChannel } = require('../../utils/validation/voiceChannelValidator');
|
||||
const { notInVoiceChannel, notInSameVoiceChannel } = require('../../utils/validation/voiceChannelValidator');
|
||||
const { SlashCommandBuilder, EmbedBuilder } = require('discord.js');
|
||||
const { useQueue } = require('discord-player');
|
||||
|
||||
@@ -34,6 +34,10 @@ module.exports = {
|
||||
});
|
||||
}
|
||||
|
||||
if (await notInSameVoiceChannel(interaction, queue)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!queue.deleted) {
|
||||
queue.setRepeatMode(0);
|
||||
queue.clear();
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
const logger = require('../../services/logger');
|
||||
const { embedOptions } = require('../../config');
|
||||
const { notInVoiceChannel } = require('../../utils/validation/voiceChannelValidator');
|
||||
const { notInVoiceChannel, notInSameVoiceChannel } = require('../../utils/validation/voiceChannelValidator');
|
||||
const { queueDoesNotExist } = require('../../utils/validation/queueValidator');
|
||||
const { SlashCommandBuilder, EmbedBuilder } = require('discord.js');
|
||||
const { useQueue } = require('discord-player');
|
||||
@@ -31,6 +31,10 @@ module.exports = {
|
||||
return;
|
||||
}
|
||||
|
||||
if (await notInSameVoiceChannel(interaction, queue)) {
|
||||
return;
|
||||
}
|
||||
|
||||
const volume = interaction.options.getNumber('percentage');
|
||||
|
||||
if (!volume && volume !== 0) {
|
||||
|
||||
@@ -8,7 +8,7 @@ exports.notInVoiceChannel = async (interaction) => {
|
||||
embeds: [
|
||||
new EmbedBuilder()
|
||||
.setDescription(
|
||||
`**${embedOptions.icons.warning} Oops!**\nYou need to be in a voice channel to use this command.`
|
||||
`**${embedOptions.icons.warning} Not in a voice channel**\nYou need to be in a voice channel to use this command.`
|
||||
)
|
||||
.setColor(embedOptions.colors.warning)
|
||||
]
|
||||
@@ -20,3 +20,26 @@ exports.notInVoiceChannel = async (interaction) => {
|
||||
|
||||
return false;
|
||||
};
|
||||
|
||||
exports.notInSameVoiceChannel = async (interaction, queue) => {
|
||||
if (!queue.dispatcher) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (interaction.member.voice.channel.id !== queue.dispatcher.channel.id) {
|
||||
await interaction.editReply({
|
||||
embeds: [
|
||||
new EmbedBuilder()
|
||||
.setDescription(
|
||||
`**${embedOptions.icons.warning} Not in same voice channel**\nYou need to be in the same voice channel as me to use this command.\n\n**Voice channel:** ${queue.dispatcher.channel.name}`
|
||||
)
|
||||
.setColor(embedOptions.colors.warning)
|
||||
]
|
||||
});
|
||||
|
||||
logger.debug(`User tried to use command ${interaction.commandName} but was not in the same voice channel.`);
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
};
|
||||
Reference in new issue
Block a user