import config from 'config'; import { NodeResolvable, useQueue } from 'discord-player'; import { EmbedBuilder, GuildMember, SlashCommandBuilder } from 'discord.js'; import loggerModule from '../../../services/logger'; import { CustomSlashCommandInteraction } from '../../../types/interactionTypes'; import { EmbedOptions } from '../../../types/configTypes'; import { notInSameVoiceChannel, notInVoiceChannel } from '../../../utils/validation/voiceChannelValidator'; const embedOptions: EmbedOptions = config.get('embedOptions'); const command: CustomSlashCommandInteraction = { isNew: false, isBeta: false, data: new SlashCommandBuilder() .setName('stop') .setDescription('Stop playing audio and clear the track queue.') .setDMPermission(false) .setNSFW(false), execute: async ({ interaction, executionId }) => { const logger = loggerModule.child({ source: 'stop.js', module: 'slashCommand', name: '/stop', executionId: executionId, shardId: interaction.guild?.shardId, guildId: interaction.guild?.id }); if (await notInVoiceChannel({ interaction, executionId })) { return Promise.resolve(); } const queue: NodeResolvable = useQueue(interaction.guild!.id)!; if (!queue) { logger.debug('There is no queue.'); logger.debug('Responding with warning embed.'); 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 Promise.resolve(); } if (!queue.deleted) { queue.setRepeatMode(0); queue.clear(); queue.node.stop(); logger.debug('Cleared and stopped the queue.'); } let authorName: string; if (interaction.member instanceof GuildMember) { authorName = interaction.member.nickname || interaction.user.username; } else { authorName = interaction.user.username; } logger.debug('Responding with success embed.'); return await interaction.editReply({ embeds: [ new EmbedBuilder() .setAuthor({ name: authorName, iconURL: interaction.user.avatarURL() || '' }) .setDescription( `**${embedOptions.icons.success} Stopped playing**\nStopped playing audio and cleared the track queue.\n\nTo play more music, use the **\`/play\`** command!` ) .setColor(embedOptions.colors.success) ] }); } }; export default command;