1

So I'm trying to make a dynamic help command that will be able to respond with commands in specific categories. For instance I would like the bot to respond as such when someone uses !help

Pick a category to show their commands:

Cat1

Cat2

Cat3

So if someone decided they wanted to see commands for Cat2, it would then display the list of commands in that specific category.

The information I have found so far on making a dynamic help command involves just displaying every command. How do I go about displaying the commands only in a specified subfolder instead?

1 Answer 1

1

Well there's one way for that, if you have a command handler (a way to make it so that uou have a folder with multiple command files and a way to use them on your main file) You could put the different command categories on each file. For example, a file like this :

module.exports = {
  name : "dosomething",
  description : "will do some stuff"
  run : (client,message,args) =>{
  // stuff
}

You could add the category key so that you define each command on your bot on a specific category :

module.exports = {
  name : "dosomething",
  description : "will do some stuff",
  category : "useful"
  run : (client,message,args) =>{
  // stuff
}

This way, every comand has it's own category. On this case you'll have to put the exact same category for every command that belongs on it.

Then, if you want to display them you can use the .filter function on your array of commands so that you only display the commands who belong on a specific category

let args = message.content.split(' ').slice(1)
let category = args[0].toLowerCase() // The first argument on the command will be the category the user asked for

let allCommands = // Here you put an array of all your commands (in most guides, it's client.commands )

let commands = allCommands.filter(command => command.category === category)

if(!commands.length) return message.channel.send(`No command found for \`${category}\``);

message.channel.send(`The commands of the category \`${category}\` are : ` +
commands.map(cmd => cmd.name) // We only want to show their names (it's not necessarly '.name', again it depends on your command handler and the key you set to have the value of the name of the command
     .join(' - ') // Since it is an array of command names we will have to convert it into a string to avoid errors.
)

If you want to show each one (for example), you could use .map on the categories themselves to show their own commands

let categories = ["Utility","NSFW","Useful","Image"...]

let embed = new Discord.MessageEmbed()
categories.map(category =>{
  category.name + ' : ' + client.commands.filter(c => c.category == category).map(c.name)
})

Note that I don't recommend you using my exact code, I only created them just now so make sure to adapt them to your variables etc..

3
  • Thank you for the information. I'll definitely need to do some fixing especially to make it as a MessageEmbed but this is exactly what I needed.
    – QuazArxx
    Oct 20, 2021 at 15:43
  • No problem, don't mind asking questions like these but I recommend you put some code on your question so you get most likely more answers
    – Bimoware
    Oct 21, 2021 at 20:19
  • Oh I know. This isn’t my first rodeo with stackoverflow. Except I had no reason to put code in since I was trying to figure out how it would be done since I didn’t even know where to begin
    – QuazArxx
    Oct 22, 2021 at 21:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.