From 49a66c0f033a112bc89ae3072c9b9c294371e203 Mon Sep 17 00:00:00 2001 From: LakhindarPal <72681474+LakhindarPal@users.noreply.github.com> Date: Wed, 12 Jun 2024 20:17:27 +0530 Subject: [PATCH] clear queue, history, all subcommand --- COMMANDS.md | 19 +++++++++---- src/commands/music/clear.js | 36 ++++++++++++++----------- src/handlers/{Command.js => command.js} | 0 src/handlers/{Event.js => event.js} | 0 4 files changed, 34 insertions(+), 21 deletions(-) rename src/handlers/{Command.js => command.js} (100%) rename src/handlers/{Event.js => event.js} (100%) diff --git a/COMMANDS.md b/COMMANDS.md index 5f0bcd2..149c4cb 100644 --- a/COMMANDS.md +++ b/COMMANDS.md @@ -188,12 +188,21 @@ Let the bot join your voice channel. --- -### `/clear` +### `/clear queue` -Clear songs from the queue, history, or all. -| Name | Description | Required | Type | Choices | -|------|-------------|----------|------|---------| -| type | Select the type of songs to clear. | true | String | Queue, History, All | +Clear songs from the queue. + +--- + +### `/clear history` + +Clear songs from the history. + +--- + +### `/clear all` + +Clear all songs from the queue and history. --- diff --git a/src/commands/music/clear.js b/src/commands/music/clear.js index 3a03cba..9cc8dbf 100644 --- a/src/commands/music/clear.js +++ b/src/commands/music/clear.js @@ -7,15 +7,19 @@ export const data = { description: "Clear songs from the queue, history, or all.", options: [ { - name: "type", - description: "Select the type of songs to clear.", - type: ApplicationCommandOptionType.String, - required: true, - choices: [ - { name: "Queue", value: "queue" }, - { name: "History", value: "history" }, - { name: "All", value: "all" }, - ], + name: "queue", + description: "Clear songs from the queue.", + type: ApplicationCommandOptionType.Subcommand, + }, + { + name: "history", + description: "Clear songs from the history.", + type: ApplicationCommandOptionType.Subcommand, + }, + { + name: "all", + description: "Clear all songs from the queue and history.", + type: ApplicationCommandOptionType.Subcommand, }, ], category: "music", @@ -24,23 +28,23 @@ export const data = { }; export function execute(interaction, queue) { - const type = interaction.options.getString("type"); + const subcmd = interaction.options.getSubcommand(); const history = useHistory(interaction.guildId); - if ((type === "queue" || type === "both") && queue.isEmpty()) { + if ((subcmd === "queue" || subcmd === "all") && queue.isEmpty()) { return interaction.reply({ ephemeral: true, - embeds: [ErrorEmbed("The queue is empty.")], + embeds: [ErrorEmbed("The queue is already empty.")], }); } - if ((type === "history" || type === "both") && history.isEmpty()) { + if ((subcmd === "history" || subcmd === "all") && history.isEmpty()) { return interaction.reply({ ephemeral: true, - embeds: [ErrorEmbed("The history is empty.")], + embeds: [ErrorEmbed("The history is already empty.")], }); } - switch (type) { + switch (subcmd) { case "queue": queue.tracks.clear(); break; @@ -55,7 +59,7 @@ export function execute(interaction, queue) { return interaction.reply({ embeds: [ SuccessEmbed( - `Cleared ${type === "all" ? "all the" : `the ${type}`} tracks.` + `Cleared ${subcmd === "all" ? "all the" : `the ${subcmd}`} tracks.` ), ], }); diff --git a/src/handlers/Command.js b/src/handlers/command.js similarity index 100% rename from src/handlers/Command.js rename to src/handlers/command.js diff --git a/src/handlers/Event.js b/src/handlers/event.js similarity index 100% rename from src/handlers/Event.js rename to src/handlers/event.js