Files
cadence-discord-bot/src/commands/player/leave.js
T

64 lines
2.3 KiB
JavaScript

const logger = require('../../services/logger');
const config = require('config');
const embedOptions = config.get('embedOptions');
const { notInVoiceChannel, notInSameVoiceChannel } = require('../../utils/validation/voiceChannelValidator');
const { SlashCommandBuilder, EmbedBuilder } = require('discord.js');
const { useQueue } = require('discord-player');
module.exports = {
isNew: false,
isBeta: false,
data: new SlashCommandBuilder()
.setName('leave')
.setDescription('Clear the track queue and remove the bot from voice channel.')
.setDMPermission(false)
.setNSFW(false),
execute: async ({ interaction, executionId }) => {
if (await notInVoiceChannel({ interaction, executionId })) {
return;
}
const queue = useQueue(interaction.guild.id);
if (!queue) {
logger.debug(
`User used command ${interaction.commandName} but there was no queue.`
);
return await interaction.editReply({
embeds: [
new EmbedBuilder()
.setDescription(
`**${embedOptions.icons.warning} Oops!**\n_Hmm.._ It seems I am not in a voice channel!`
)
.setColor(embedOptions.colors.warning)
]
});
}
if (await notInSameVoiceChannel({ interaction, queue, executionId })) {
return;
}
if (!queue.deleted) {
queue.delete();
logger.debug(
`User used command ${interaction.commandName} and deleted the queue.`
);
}
return await interaction.editReply({
embeds: [
new EmbedBuilder()
.setAuthor({
name: interaction.member.nickname || interaction.user.username,
iconURL: interaction.user.avatarURL()
})
.setDescription(
`**${embedOptions.icons.success} Leaving channel**\nCleared the track queue and left voice channel.\n\nTo play more music, use the **\`/play\`** command!`
)
.setColor(embedOptions.colors.success)
]
});
}
};