Advertisement
Guest User

Untitled

a guest
Jul 12th, 2018
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.74 KB | None | 0 0
  1. const Discord = require("discord.js");
  2. const fs = require("fs");
  3. const config = require("../auth.json");
  4. const commands = JSON.parse(fs.readFileSync("storage/commands.json", "utf-8"));
  5.  
  6.  
  7. exports.run = async (client, message, args, command, level) => { // eslint-disable-line no-unused-vars
  8.  
  9.  
  10. // Start of the embed
  11. const embed = new Discord.RichEmbed()
  12. .setColor(0x1D82B6) // You can set this color to whatever you want.
  13.  
  14. // Variables
  15. let commandsFound = 0; // We also want to tell them how many commands there are for that specific group.
  16.  
  17. // Lets create the for loop that loops through the commands
  18. for (var cmd in commands) { // We should start creating the commands json first.
  19. // Checks if the group is "users" - and replace type with group
  20. if (commands[cmd].group.toUpperCase() === 'USER') {
  21. // Lets also count commandsFound + 1 every time it finds a command in the group
  22. commandsFound++
  23. // Lets add the command field to the embed
  24. console.log(commands[cmd].name);
  25. embed.addField(`${commands[cmd].name}`, `**Description:** ${commands[cmd].desc}\n**Usage:** ${config.prefix + commands[cmd].usage}`, true); // This will output something like <commandname>[title] [newline] desc: <description> [newline] usage: <usage
  26. }
  27. }
  28.  
  29. // Add some more to the embed - we need to move that out of the for loop.
  30. embed.addBlankField(true)
  31. embed.setFooter(`Currently showing user commands. To view another group do ${config.prefix}help [group / command]`)
  32. embed.setDescription(`**${commandsFound} commands found** - [] means required, <> means optional`)
  33.  
  34.  
  35. if (message.guild) {
  36. // We can output it two ways. 1 - Send to DMs, and tell them that they sent to DMs in chat. 2 - Post commands in chat. [since commands take up a lot let's send to DMs]
  37. message.author.send({embed})
  38.  
  39. // Post in chat they sent to DMs
  40. message.channel.send({embed: {
  41. color: 0x1D82B6,
  42. description: `**Check your DMs ${message.author}!**`
  43. }});
  44. } else {
  45. message.author.send({embed})
  46. }
  47.  
  48. // Let's test this! - We have a few bugs first though.
  49. // Turns out you can only use the word embed to define embeds.
  50.  
  51.  
  52. if (args.join(" ").toUpperCase() === 'GROUPS') {
  53.  
  54. // Variables
  55. let groups = '';
  56.  
  57. for (var cmd in commands) {
  58. if (!groups.includes(commands[cmd].group)) {
  59. groups += `${commands[cmd].group}\n`
  60. }
  61. }
  62.  
  63. message.channel.send({embed: {
  64. description:`**${groups}**`,
  65. title:"Groups",
  66. color: 0x1D82B6
  67. }})
  68.  
  69. return; // Testing!
  70.  
  71.  
  72. } else {
  73. // Now, lets do something when they do ~help [cmd / group] - You can use copy and paste for a lot of this part.
  74.  
  75. // Variables
  76. let groupFound = '';
  77.  
  78. for (var cmd in commands) { // This will see if their is a group named after what the user entered.
  79.  
  80. if (args.join(" ").trim().toUpperCase() === commands[cmd].group.toUpperCase()) {
  81. groupFound = commands[cmd].group.toUpperCase(); // Lets set the ground found, then break out of the loop.
  82. break;
  83. }
  84.  
  85. }
  86.  
  87. if (groupFound != '') { // If a group is found, run this statement.
  88.  
  89. // Start of the embed
  90. const embed = new Discord.RichEmbed()
  91. .setColor(0x1D82B6) // You can set this color to whatever you want.
  92.  
  93. // Variables
  94. let commandsFound = 0; // We also want to tell them how many commands there are for that specific group.
  95.  
  96.  
  97. for (var cmd in commands) { // We can use copy and paste again
  98.  
  99. // Checks if the group is "users" - and replace type with group
  100. if (commands[cmd].group.toUpperCase() === groupFound) {
  101. // Lets also count commandsFound + 1 every time it finds a command in the group
  102. commandsFound++
  103. // Lets add the command field to the embed
  104. embed.addField(`${commands[cmd].name}`, `**Description:** ${commands[cmd].desc}\n**Usage:** ${config.prefix + commands[cmd].usage}`); // This will output something like <commandname>[title] [newline] desc: <description> [newline] usage: <usage
  105. }
  106.  
  107. }
  108.  
  109. // Add some more to the embed - we need to move that out of the for loop.
  110. embed.setFooter(`Currently showing ${groupFound} commands. To view another group do ${config.prefix}help [group / command]`)
  111. embed.setDescription(`**${commandsFound} commands found** - [] means required, <> means optional`)
  112.  
  113. if (message.guild) {
  114. // We can output it two ways. 1 - Send to DMs, and tell them that they sent to DMs in chat. 2 - Post commands in chat. [since commands take up a lot let's send to DMs]
  115. message.author.send({embed})
  116.  
  117. // Post in chat they sent to DMs
  118. message.channel.send({embed: {
  119. color: 0x1D82B6,
  120. description: `**Check your DMs ${message.author}!**`
  121. }})
  122. } else {
  123. message.author.send({embed})
  124. }
  125.  
  126. // Make sure you copy and paste into the right place, lets test it now!
  127. return; // We want to make sure we return so it doesnt run the rest of the script after it finds a group! Lets test it!
  128.  
  129. // Now lets show groups.
  130. }
  131.  
  132. // Although, if a group is not found, lets see if it is a command
  133.  
  134. // Variables
  135. let commandFound = '';
  136. let commandDesc = '';
  137. let commandUsage = '';
  138. let commandGroup = '';
  139.  
  140. for (var cmd in commands) { // Copy and paste
  141.  
  142. if (args.join(" ").trim().toUpperCase() === commands[cmd].name.toUpperCase()) {
  143. commandFound = commands[cmd].name; // Lets change this so it doesnt make it go uppcase
  144. commandDesc = commands[cmd].desc;
  145. commandUsage = commands[cmd].usage;
  146. commandGroup = commands[cmd].group;
  147. break;
  148. }
  149.  
  150. }
  151.  
  152. // Lets post in chat if nothing is found!
  153. /*if (commandFound === '') {
  154. message.channel.send({embed: {
  155. description:`**No group or command found titled \`${args.join(" ")}\`**`,
  156. color: 0x1D82B6,
  157. }})
  158.  
  159. } */
  160.  
  161. // Since this one is smaller, lets send the embed differently.
  162. message.channel.send({embed: {
  163. title:'[] means required, <> means optional',
  164. color: 0x1D82B6,
  165. fields: [{
  166. name:commandFound,
  167. value:`**Description:** ${commandDesc}\n**Usage:** ${commandUsage}\n**Group:** ${commandGroup}`
  168. }]
  169. }})
  170.  
  171. return; // We want to return here so that it doesnt run the rest of the script also.
  172. }
  173. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement