Advertisement
battlingmean1

Untitled

May 23rd, 2020
50
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.93 KB | None | 0 0
  1. exports.run = (client, message, args, level) => {
  2. // If no specific command is called, show all filtered commands.
  3. if (!args[0]) {
  4. // Filter all commands by which are available for the user's level, using the <Collection>.filter() method.
  5. const myCommands = message.guild ? client.commands.filter(cmd => client.levelCache[cmd.conf.permLevel] <= level) : client.commands.filter(cmd => client.levelCache[cmd.conf.permLevel] <= level && cmd.conf.guildOnly !== true);
  6.  
  7. // Here we have to get the command names only, and we use that array to get the longest name.
  8. // This make the help commands "aligned" in the output.
  9. const commandNames = myCommands.keyArray();
  10. const longest = commandNames.reduce((long, str) => Math.max(long, str.length), 0);
  11.  
  12. let currentCategory = "";
  13. let output = `= Command List =\n\n[Use ${message.settings.prefix}help <commandname> for details]\n`;
  14. const sorted = myCommands.array().sort((p, c) => p.help.category > c.help.category ? 1 : p.help.name > c.help.name && p.help.category === c.help.category ? 1 : -1 );
  15. sorted.forEach( c => {
  16. const cat = c.help.category.toProperCase();
  17. if (currentCategory !== cat) {
  18. output += `\u200b\n== ${cat} ==\n`;
  19. currentCategory = cat;
  20. }
  21. output += `${message.settings.prefix}${c.help.name}${" ".repeat(longest - c.help.name.length)} :: ${c.help.description}\n`;
  22. });
  23. message.channel.send(output, {code: "asciidoc", split: { char: "\u200b" }});
  24. } else {
  25. // Show individual command's help.
  26. let command = args[0];
  27. if (client.commands.has(command)) {
  28. command = client.commands.get(command);
  29. if (level < client.levelCache[command.conf.permLevel]) return;
  30. message.channel.send(`= ${command.help.name} = \n${command.help.description}\nusage:: ${command.help.usage}\naliases:: ${command.conf.aliases.join(", ")}\n= ${command.help.name} =`, {code:"asciidoc"});
  31. }
  32. }
  33. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement