Skip to content

Commit

Permalink
clear queue, history, all subcommand
Browse files Browse the repository at this point in the history
  • Loading branch information
LakhindarPal committed Jun 12, 2024
1 parent a8c5b05 commit 49a66c0
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 21 deletions.
19 changes: 14 additions & 5 deletions COMMANDS.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

---

Expand Down
36 changes: 20 additions & 16 deletions src/commands/music/clear.js
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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;
Expand All @@ -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.`
),
],
});
Expand Down
File renamed without changes.
File renamed without changes.

0 comments on commit 49a66c0

Please sign in to comment.