Skip to content

Commit

Permalink
[New] help command will now show commands by category or all availabl…
Browse files Browse the repository at this point in the history
…e commands!
  • Loading branch information
naseif committed Sep 2, 2021
1 parent a1e8cc4 commit 7d695aa
Showing 1 changed file with 43 additions and 10 deletions.
53 changes: 43 additions & 10 deletions commands/misc/help.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,54 @@ const { SlashCommandBuilder } = require("@discordjs/builders");
module.exports = {
data: new SlashCommandBuilder()
.setName("help")
.setDescription("Shows all available commands for this bot!"),
.setDescription("Shows all available commands for this bot!")
.addStringOption((option) =>
option
.setName("category")
.setDescription("show help by category")
.addChoice("Admin", "admin")
.addChoice("Fun", "fun")
.addChoice("Music", "music")
.addChoice("Misc", "misc")
),
async execute(interaction, client) {
await interaction.deferReply();
const commands = client.commands.map(
(command) =>
"```" +
`/${command.data.name}` +
"```" +
"- " +
`**${command.data.description}**`
);
const category = interaction.options.getString("category");

function printHelpByCollection(collection) {
const commands = collection.map(
(command) =>
"```" +
`/${command.data.name}` +
"```" +
"- " +
`**${command.data.description}**`
);
return commands;
}

let help;
switch (category) {
case "admin":
help = printHelpByCollection(client.commands.admin);
break;
case "fun":
help = printHelpByCollection(client.commands.fun);
break;
case "music":
help = printHelpByCollection(client.commands.music);
break;
case "misc":
help = printHelpByCollection(client.commands.misc);
break;
default:
help = printHelpByCollection(client.commands);
}

const embed = {
color: "#9dcc37",
title: `${client.user.username}'s Commands!`,
description: `${commands.join("\n")}`,
description: `${help.join("\n")}`,
author: {
name: `${interaction.user.username}`,
icon_url: `${interaction.user.avatarURL()}`,
Expand Down

0 comments on commit 7d695aa

Please sign in to comment.