From b95a652f1c18f1816a4a47c3197549487f33e545 Mon Sep 17 00:00:00 2001 From: Marius Begby Date: Sun, 23 Jul 2023 14:55:53 +0200 Subject: [PATCH] feat: Updated /help command to be dynamic --- src/commands/info/help.js | 37 +++++++++++++++++++++++++++++-- src/commands/player/filters.js | 5 ++++- src/commands/player/leave.js | 7 +++--- src/commands/player/loop.js | 3 +++ src/commands/player/nowplaying.js | 5 ++++- src/commands/player/pause.js | 5 ++++- src/commands/player/play.js | 3 +++ src/commands/player/queue.js | 3 +++ src/commands/player/remove.js | 3 +++ src/commands/player/seek.js | 3 +++ src/commands/player/skip.js | 3 +++ src/commands/player/stop.js | 7 +++--- src/commands/player/volume.js | 3 +++ src/commands/system/guilds.js | 5 ++++- src/commands/system/status.js | 8 ++++++- 15 files changed, 87 insertions(+), 13 deletions(-) diff --git a/src/commands/info/help.js b/src/commands/info/help.js index f6e4e62..a5e6496 100644 --- a/src/commands/info/help.js +++ b/src/commands/info/help.js @@ -5,8 +5,40 @@ module.exports = { data: new SlashCommandBuilder() .setName('help') .setDescription('Show a list of commands and their usage.') - .setDMPermission(false), - execute: async ({ interaction }) => { + .setDMPermission(false) + .setNSFW(false), + execute: async ({ interaction, client }) => { + const commandList = client.commands + .filter((command) => { + // don't include system commands + if (command.isSystemCommand) { + return false; + } + return true; + }) + .map((command) => { + let params = command.data.options[0] ? `**\`${command.data.options[0].name}\`**` + ' ' : ''; + let beta = command.isBeta ? `${embedOptions.icons.beta} ` : ''; + let newCommand = command.isNew ? `${embedOptions.icons.new} ` : ''; + return `- **\`/${command.data.name}\`** ${params}- ${beta}${newCommand}${command.data.description}`; + }); + + const commandListString = commandList.join('\n'); + + return await interaction.editReply({ + embeds: [ + new EmbedBuilder() + .setDescription( + `${embedOptions.icons.rule} **List of commands**\n` + + `${commandListString}\n\n` + + `${embedOptions.icons.support} **Support server**\nJoin the support server for help or suggestions: \n**${botOptions.serverInviteUrl}**\n\n` + + `${embedOptions.icons.bot} **Enjoying ${botOptions.name}?**\nAdd me to another server: \n**[Click me!](${botOptions.botInviteUrl})**` + ) + .setColor(embedOptions.colors.info) + ] + }); + + /* return await interaction.editReply({ embeds: [ new EmbedBuilder() @@ -30,5 +62,6 @@ module.exports = { .setColor(embedOptions.colors.info) ] }); + */ } }; diff --git a/src/commands/player/filters.js b/src/commands/player/filters.js index 1622f85..68b89c6 100644 --- a/src/commands/player/filters.js +++ b/src/commands/player/filters.js @@ -13,10 +13,13 @@ const { const { useQueue } = require('discord-player'); module.exports = { + isNew: false, + isBeta: true, data: new SlashCommandBuilder() .setName('filters') .setDescription('Toggle various audio filters during playback.') - .setDMPermission(false), + .setDMPermission(false) + .setNSFW(false), execute: async ({ interaction }) => { if (await notInVoiceChannel(interaction)) { return; diff --git a/src/commands/player/leave.js b/src/commands/player/leave.js index db0860b..713a049 100644 --- a/src/commands/player/leave.js +++ b/src/commands/player/leave.js @@ -5,12 +5,13 @@ 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), - - // todo, allow command to be executed if bot is only member in voice channel + .setDMPermission(false) + .setNSFW(false), execute: async ({ interaction }) => { if (await notInVoiceChannel(interaction)) { return; diff --git a/src/commands/player/loop.js b/src/commands/player/loop.js index 2e536b2..87ec55b 100644 --- a/src/commands/player/loop.js +++ b/src/commands/player/loop.js @@ -6,10 +6,13 @@ const { SlashCommandBuilder, EmbedBuilder } = require('discord.js'); const { useQueue } = require('discord-player'); module.exports = { + isNew: false, + isBeta: true, data: new SlashCommandBuilder() .setName('loop') .setDescription('Toggle looping a track, the whole queue or autoplay.') .setDMPermission(false) + .setNSFW(false) .addStringOption((option) => option .setName('mode') diff --git a/src/commands/player/nowplaying.js b/src/commands/player/nowplaying.js index 9b00bf8..182bfc0 100644 --- a/src/commands/player/nowplaying.js +++ b/src/commands/player/nowplaying.js @@ -6,10 +6,13 @@ const { SlashCommandBuilder, EmbedBuilder, ActionRowBuilder, ButtonBuilder } = r const { useQueue } = require('discord-player'); module.exports = { + isNew: false, + isBeta: false, data: new SlashCommandBuilder() .setName('nowplaying') .setDescription('Show information about the track currently playing.') - .setDMPermission(false), + .setDMPermission(false) + .setNSFW(false), execute: async ({ interaction }) => { if (await notInVoiceChannel(interaction)) { return; diff --git a/src/commands/player/pause.js b/src/commands/player/pause.js index f60ee75..0a2c3c1 100644 --- a/src/commands/player/pause.js +++ b/src/commands/player/pause.js @@ -6,10 +6,13 @@ const { SlashCommandBuilder, EmbedBuilder } = require('discord.js'); const { useQueue } = require('discord-player'); module.exports = { + isNew: false, + isBeta: false, data: new SlashCommandBuilder() .setName('pause') .setDescription('Pause or resume the current track.') - .setDMPermission(false), + .setDMPermission(false) + .setNSFW(false), execute: async ({ interaction }) => { if (await notInVoiceChannel(interaction)) { return; diff --git a/src/commands/player/play.js b/src/commands/player/play.js index bb9db46..44f1318 100644 --- a/src/commands/player/play.js +++ b/src/commands/player/play.js @@ -7,10 +7,13 @@ const { SlashCommandBuilder, EmbedBuilder } = require('discord.js'); const { useMainPlayer, useQueue } = require('discord-player'); module.exports = { + isNew: false, + isBeta: false, data: new SlashCommandBuilder() .setName('play') .setDescription('Add a track or playlist to the queue by searching or url.') .setDMPermission(false) + .setNSFW(false) .addStringOption((option) => option .setName('query') diff --git a/src/commands/player/queue.js b/src/commands/player/queue.js index ae8e64d..9eebfd8 100644 --- a/src/commands/player/queue.js +++ b/src/commands/player/queue.js @@ -5,10 +5,13 @@ const { SlashCommandBuilder, EmbedBuilder } = require('discord.js'); const { useQueue } = require('discord-player'); module.exports = { + isNew: false, + isBeta: false, data: new SlashCommandBuilder() .setName('queue') .setDescription('Show the list of tracks added to the queue.') .setDMPermission(false) + .setNSFW(false) .addNumberOption((option) => option.setName('page').setDescription('Page number of the queue').setMinValue(1)), execute: async ({ interaction }) => { if (await notInVoiceChannel(interaction)) { diff --git a/src/commands/player/remove.js b/src/commands/player/remove.js index e208a9b..e371dff 100644 --- a/src/commands/player/remove.js +++ b/src/commands/player/remove.js @@ -6,10 +6,13 @@ const { SlashCommandBuilder, EmbedBuilder } = require('discord.js'); const { useQueue } = require('discord-player'); module.exports = { + isNew: false, + isBeta: false, data: new SlashCommandBuilder() .setName('remove') .setDescription('Remove a specific track from the queue.') .setDMPermission(false) + .setNSFW(false) .addNumberOption((option) => option .setName('tracknumber') diff --git a/src/commands/player/seek.js b/src/commands/player/seek.js index e7c6635..e5bd3f7 100644 --- a/src/commands/player/seek.js +++ b/src/commands/player/seek.js @@ -6,10 +6,13 @@ const { SlashCommandBuilder, EmbedBuilder } = require('discord.js'); const { useQueue } = require('discord-player'); module.exports = { + isNew: false, + isBeta: false, data: new SlashCommandBuilder() .setName('seek') .setDescription('Seek to a specified duration in the current track.') .setDMPermission(false) + .setNSFW(false) .addStringOption((option) => option .setName('duration') diff --git a/src/commands/player/skip.js b/src/commands/player/skip.js index d4a886e..18a1645 100644 --- a/src/commands/player/skip.js +++ b/src/commands/player/skip.js @@ -6,10 +6,13 @@ const { SlashCommandBuilder, EmbedBuilder } = require('discord.js'); const { useQueue } = require('discord-player'); module.exports = { + isNew: false, + isBeta: false, data: new SlashCommandBuilder() .setName('skip') .setDescription('Skip current or specified track.') .setDMPermission(false) + .setNSFW(false) .addNumberOption((option) => option.setName('tracknumber').setDescription('Track number to skip to in the queue.').setMinValue(1) ), diff --git a/src/commands/player/stop.js b/src/commands/player/stop.js index 4ff9451..7ac9ef4 100644 --- a/src/commands/player/stop.js +++ b/src/commands/player/stop.js @@ -5,12 +5,13 @@ const { SlashCommandBuilder, EmbedBuilder } = require('discord.js'); const { useQueue } = require('discord-player'); module.exports = { + isNew: true, + isBeta: false, data: new SlashCommandBuilder() .setName('stop') .setDescription('Stop playing audio and clear the track queue.') - .setDMPermission(false), - - // todo, allow command to be executed if bot is only member in voice channel + .setDMPermission(false) + .setNSFW(false), execute: async ({ interaction }) => { if (await notInVoiceChannel(interaction)) { return; diff --git a/src/commands/player/volume.js b/src/commands/player/volume.js index f4dc3ea..efbaf4b 100644 --- a/src/commands/player/volume.js +++ b/src/commands/player/volume.js @@ -6,10 +6,13 @@ const { SlashCommandBuilder, EmbedBuilder } = require('discord.js'); const { useQueue } = require('discord-player'); module.exports = { + isNew: false, + isBeta: false, data: new SlashCommandBuilder() .setName('volume') .setDescription('Show or set the playback volume for tracks.') .setDMPermission(false) + .setNSFW(false) .addNumberOption((option) => option .setName('percentage') diff --git a/src/commands/system/guilds.js b/src/commands/system/guilds.js index 10c46bb..f37e28e 100644 --- a/src/commands/system/guilds.js +++ b/src/commands/system/guilds.js @@ -5,10 +5,13 @@ const { SlashCommandBuilder, EmbedBuilder } = require('discord.js'); module.exports = { isSystemCommand: true, + isNew: false, + isBeta: false, data: new SlashCommandBuilder() .setName('guilds') .setDescription('Show list of guilds where bot is added.') - .setDMPermission(false), + .setDMPermission(false) + .setNSFW(false), execute: async ({ interaction, client }) => { if (await notValidGuildId(interaction)) { logger.debug(`[Shard ${client.shard.ids[0]}] Not a valid guild id.`); diff --git a/src/commands/system/status.js b/src/commands/system/status.js index 26d7f39..ed20378 100644 --- a/src/commands/system/status.js +++ b/src/commands/system/status.js @@ -7,7 +7,13 @@ const { version, dependencies } = require('../../../package.json'); module.exports = { isSystemCommand: true, - data: new SlashCommandBuilder().setName('status').setDescription('Show bot status.').setDMPermission(false), + isNew: false, + isBeta: false, + data: new SlashCommandBuilder() + .setName('status') + .setDescription('Show bot status.') + .setDMPermission(false) + .setNSFW(false), execute: async ({ interaction, client }) => { if (await notValidGuildId(interaction)) { return;