GamearooCodes

Untitled

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