diff --git a/commands/remove.js b/commands/remove.js new file mode 100644 index 0000000..bbbed7a --- /dev/null +++ b/commands/remove.js @@ -0,0 +1,76 @@ +const { SlashCommandBuilder } = require('@discordjs/builders'); +const { useMainPlayer, useQueue } = require('discord-player'); +const { EmbedBuilder } = require('discord.js'); +const { embedColors } = require('../config.json'); + +module.exports = { + data: new SlashCommandBuilder() + .setName('remove') + .setDescription('Remove a track from the queue.') + .addNumberOption((option) => + option + .setName('tracknumber') + .setDescription('Remove specified track number from queue.') + .setMinValue(1) + .setRequired(true) + ), + run: async ({ interaction }) => { + if (!interaction.member.voice.channel) { + return interaction.editReply({ + embeds: [ + new EmbedBuilder() + .setDescription( + `**Failed**\nYou need to be in a voice channel to use this command.` + ) + .setColor(embedColors.colorWarning) + ] + }); + } + + const queue = useQueue(interaction.guild.id); + + if (!queue) { + return await interaction.editReply({ + embeds: [ + new EmbedBuilder() + .setDescription( + `**Failed**\nThere are no tracks in the queue.` + ) + .setColor(embedColors.colorWarning) + ] + }); + } + + const removeTrackNumber = interaction.options.getNumber('tracknumber'); + + if (removeTrackNumber > queue.tracks.data.length) { + return await interaction.editReply({ + embeds: [ + new EmbedBuilder() + .setDescription( + `**Error**\nThere are \`${queue.tracks.data.length}\` tracks in the queue. You cannot remove track number \`${removeTrackNumber}\`.` + ) + .setColor(embedColors.colorError) + ] + }); + } + + // Remove specified track number from queue + const removedTrack = queue.node.remove(removeTrackNumber - 1); + + return await interaction.editReply({ + embeds: [ + new EmbedBuilder() + .setAuthor({ + name: interaction.user.username, + iconURL: interaction.user.avatarURL() + }) + .setDescription( + `**Removed**\n**[${removedTrack.title}](${removedTrack.url})**.` + ) + .setThumbnail(removedTrack.thumbnail) + .setColor(embedColors.colorSuccess) + ] + }); + } +}; diff --git a/commands/skip.js b/commands/skip.js index bd9d655..e4b34cc 100644 --- a/commands/skip.js +++ b/commands/skip.js @@ -44,7 +44,7 @@ module.exports = { if (skipToTrack) { if (skipToTrack > queue.tracks.data.length) { - await interaction.editReply({ + return await interaction.editReply({ embeds: [ new EmbedBuilder() .setDescription( @@ -57,7 +57,7 @@ module.exports = { const skippedTrack = queue.currentTrack; queue.node.skipTo(skipToTrack - 1); - await interaction.editReply({ + return await interaction.editReply({ embeds: [ new EmbedBuilder() .setAuthor({ @@ -76,7 +76,7 @@ module.exports = { const skippedTrack = queue.currentTrack; queue.node.skip(); - await interaction.editReply({ + return await interaction.editReply({ embeds: [ new EmbedBuilder() .setAuthor({