Skip to content

Instantly share code, notes, and snippets.

@Mr-KayJayDee
Last active May 25, 2020 22:18
Show Gist options
  • Save Mr-KayJayDee/ec46fc3448180ed3319c607b1548239e to your computer and use it in GitHub Desktop.
Save Mr-KayJayDee/ec46fc3448180ed3319c607b1548239e to your computer and use it in GitHub Desktop.
//Get the discord.js library
const Discord = require("discord.js")
// Define the object
const cmd = {};
// For each key in the bot commands (replace this.client.commands by for example client.commands oo bot.commands )
for (const key of this.client.commands) {
//If the category of the command ins't in the object, push it in
if (!cmd[key[1].help.category]) {
cmd[key[1].help.category] = [];
};
cmd[key[1].help.category].push(key[1]);
};
//Define the mbed that will display all the sorted commands
const embed = new Discord.RichEmbed() //or new Discord.MessageEmbed() (for v12 users)
.setTitle("Here is a list of all the available commands");
//For every categories add a field to our embed with the category name as a title and a list of all the command in the category
for (const key in cmd) {
embed.addField(`**${cmd[key].length} · ${key}**`, `\`${cmd[key].map((v) => v.help.name).join('`, `')}\``)
// amount of command the catgeory the list of all the commands separated with ", "
// in this category name
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment