GamearooCodes

Untitled

Sep 11th, 2022
168
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.33 KB | None | 0 0
  1. //! Dependency Imports
  2. const { EmbedBuilder, ActionRowBuilder, SelectMenuBuilder, ComponentType } = require("discord.js");
  3. const fs = require("fs");
  4.  
  5. //! Client Imports
  6. const { prefix } = require("../../../config.js");
  7. const Logger = require("../../classes/Logger.js");
  8.  
  9. module.exports = {
  10. name: "help",
  11. category: "General",
  12. description: "The Help Menu that shows all the available commands.",
  13. aliases: ["cmds", "commands"],
  14. async execute(XyroClient, message, args) {
  15. let dirs = [];
  16. let categories = [];
  17. let page = 0;
  18.  
  19. const menuOpts = [
  20. {
  21. label: `Home`,
  22. description: `Home Page`,
  23. emoji: "🏡",
  24. value: `home`,
  25. }
  26. ]
  27. const emojis = {
  28. General: "📘",
  29. Fun: "🎉",
  30. Economy: "💵"
  31. }
  32. const description = {
  33. General: "Where all the General Commands are stored",
  34. Fun: "Where all the Fun Comamnds are stored",
  35. Economy: "Where all the Economy Commands are stored"
  36. }
  37.  
  38.  
  39. // const editedRow = new ActionRowBuilder()
  40. fs.readdirSync('./src/commands/').forEach((dir) => {
  41. const commands = fs.readdirSync('./src/commands/' + dir).filter(file => file.endsWith(".js"));
  42. const cmds = commands.map((cmd) => {
  43. let file = require(`../../commands/${dir}/${cmd}`);
  44. return {
  45. name: dir,
  46. commands: {
  47. name: file.name,
  48. category: file.category,
  49. description: file.description
  50. }
  51. }
  52. })
  53.  
  54. categories.push(cmds.filter(cat => cat.name === dir));
  55. })
  56.  
  57. categories.forEach((cat) => {
  58. dirs.push(cat[0].name);
  59. });
  60.  
  61. dirs.forEach((dir) => {
  62. menuOpts.push(
  63. {
  64. label: `${dir}`,
  65. description: `${dir} comamnds page`,
  66. emoji: `${emojis[dir] || ''}`,
  67. value: `${page++}`,
  68. }
  69. )
  70. })
  71.  
  72. let menu = new SelectMenuBuilder()
  73. .setCustomId('help_menu')
  74. .setPlaceholder('Select a Category')
  75. .addOptions(menuOpts)
  76. .setDisabled(false)
  77.  
  78. var row = new ActionRowBuilder()
  79. .addComponents(menu);
  80.  
  81.  
  82. const helpMenuEmbed = new EmbedBuilder()
  83. .setColor(0xb5c0ff)
  84. .setTitle(`${XyroClient.user.username}'s Help Menu 📚`)
  85. .setDescription(`Hi! Im a multipurpose bot with many functions. If you ever need my prefix, my prefix is \`${prefix}\``);
  86.  
  87. let msg = await message.channel.send({ embeds: [helpMenuEmbed], components: [row] });
  88.  
  89. const filter = i => !i.user.bot;
  90. const collector = message.channel.createMessageComponentCollector({
  91. filter,
  92. componentType: ComponentType.SelectMenu,
  93. time: 20000
  94. });
  95.  
  96. collector.on('collect', async (interaction) => {
  97. const value = interaction.values[0];
  98.  
  99. if (interaction.user.id !== message.author.id) return;
  100. if (interaction.customId !== 'help_menu') return;
  101. interaction.deferUpdate();
  102.  
  103.  
  104. if (value && value !== 'home') {
  105. helpMenuEmbed.setFields();
  106. helpMenuEmbed.setDescription('\u200B')
  107. helpMenuEmbed.setTitle(`${emojis[categories[value][0].name] ? emojis[categories[value][0].name] : ""} Help Menu | ${categories[value][0].name}`)
  108.  
  109. categories[value].forEach((cmd) => {
  110. helpMenuEmbed.addFields(
  111. { name: `\`${prefix}${cmd.commands.name || ''}\``, value: `${cmd.commands.description || 'No Description Set'}\n${cmd.commands.category}`, inline: true }
  112. )
  113. })
  114. }
  115.  
  116. msg = await msg.edit({ embeds: [helpMenuEmbed], components: [row] });
  117.  
  118. if (value === 'home') {
  119. helpMenuEmbed.setFields()
  120. .setDescription(`Hi! Im a multipurpose bot with many functions. If you ever need my prefix, my prefix is \`${prefix}\``);
  121. helpMenuEmbed.setTitle(`${XyroClient.user.username}'s Help Menu`)
  122.  
  123. dirs.forEach((dir) => {
  124. helpMenuEmbed.addFields(
  125. {
  126. name: `${emojis[dir] || ''} ${dir.charAt(0).toUpperCase() + dir.slice(1).toLowerCase()}`,
  127. value: `${description[dir] ? description[dir] : `${dir.charAt(0).toUpperCase() + dir.slice(1).toLowerCase()} Commands`}`,
  128. inline: false
  129. }
  130. )
  131. })
  132. }
  133.  
  134. msg = await msg.edit({ embeds: [helpMenuEmbed], components: [row] });
  135.  
  136. })
  137.  
  138. collector.on('end', async (interaction) => {
  139. menu.setDisabled(true)
  140. row = new ActionRowBuilder()
  141. .addComponents(menu);
  142.  
  143. await msg.edit({ embeds: [helpMenuEmbed], components: [editedRow] });
  144. await Logger.success("Disabled Select Menu");
  145. })
  146. }
  147. }
Advertisement
Add Comment
Please, Sign In to add comment