Advertisement
Guest User

Untitled

a guest
Sep 18th, 2019
150
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.81 KB | None | 0 0
  1. const settings = require("../bot/settings.json");
  2. const Discord = require("discord.js");
  3. const fs = require("fs");
  4. const ms = require("ms");
  5.  
  6. module.exports.run = async (bot, message, args) => {
  7. let prefix = settings.prefix;
  8. let total = 0;
  9. let commandList = [];
  10. if (!args[0]) {
  11. let page = 1;
  12.  
  13. message.reply("Please tell me which page you want me to show")
  14. } else {
  15. if (isNaN(Number(args[0]))) {
  16. message.reply("From " + total + " commands i have, this one was not found");
  17. } else {
  18. let page = parseInt(args[0], 10);
  19. }
  20. }
  21.  
  22. fs.readdir("./commands/", (err, files) => {
  23. if (err) {
  24. console.error("An error has occured while loading commands: ");
  25. console.error(err);
  26. }
  27.  
  28. let jsFile = files.filter(file => file.split(".").pop() == "js");
  29. let messageSended = false;
  30.  
  31.  
  32. jsFile.forEach((file, i) => {
  33. let props = require(`./${file}`);
  34. bot.commands.set(props.help.command, props);
  35.  
  36. props.help.aliases.forEach(alias => {
  37. bot.aliases.set(alias, props.help.command);
  38. });
  39. total++;
  40. commandList.push({
  41. "name": props.help.name,
  42. "info": props.help.helpInfo,
  43. "aliases": props.help.aliases
  44. })
  45. }
  46.  
  47. })
  48. //console.log("props.help.command=" + props.help.command);
  49. //console.log("props.help.aliases= " + props.help.aliases);
  50. //console.log("args[0]= " + args[0]);
  51. //console.log("props.helpInfo= " + props.helpInfo);
  52. //console.log("props.help.helpInfo= "+ props.help.helpInfo);
  53.  
  54.  
  55.  
  56.  
  57.  
  58.  
  59.  
  60.  
  61. let max = Math.ceil(total / 5);
  62.  
  63. if (page <= 0 || page > (max)) {
  64. message.reply("Please put a valid number, between 1 and " + max);
  65. } else {
  66. let commandShow = commandList.slice(args[0] * 5 - 5, args[0] * 5);
  67. console.log(commandShow)
  68.  
  69. // creation of embed
  70. const embed = new Discord.RichEmbed()
  71. .setTitle("Commands available:")
  72. .setFooter(`Page${args[0]}/${max}`)
  73. .setColor("RANDOM");
  74. //message.reply("List of all commands: " + commandList);
  75.  
  76. // upgrade to embed
  77. let testArray = ["1", "2", "3"]
  78. // for better embed, have only one field for all commands
  79. let embedMessage = "";
  80. commandShow.forEach((commandName) => {
  81. embedMessage = embedMessage + `__**${commandName.name}**__:\n **description: \n** ${commandName.info} \n **aliases:** \n ${commandName.aliases} \n\n`
  82. });
  83. embed.setDescription(embedMessage);
  84. message.channel.send(embed);
  85.  
  86. }
  87.  
  88.  
  89.  
  90.  
  91.  
  92. };
  93.  
  94.  
  95. module.exports.help = {
  96. name: "Help",
  97. command: "help",
  98. aliases: [NaN],
  99. helpInfo: ["help info"]
  100. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement