help.js (6785B)
1 const { 2 EmbedBuilder, 3 Client, 4 CommandInteraction, 5 ActionRowBuilder, 6 StringSelectMenuBuilder, 7 ComponentType, 8 } = require("discord.js"); 9 const Utils = require("../../util/functions/function"); 10 module.exports = { 11 name: "help", 12 usage: "(Command/Category)", 13 description: "Shows all available bot commands", 14 category: "Information", 15 options: [ 16 { 17 type: 3, 18 name: "command", 19 description: "The command you want to see", 20 required: false, 21 }, 22 ], 23 /** 24 * 25 * @param {Client} client 26 * @param {CommandInteraction} interaction 27 * @param {String[]} args 28 * @param {Utils} utils 29 */ 30 run: async (client, interaction, args, utils) => { 31 if (!args[0]) { 32 await interaction.deleteReply(); 33 const emoji = { 34 CODM: "<a:codm:897030768793104385>", 35 APEX: "🎆", 36 Config: "<a:config:896990033561669762>", 37 Information: "<a:information:894962394932064346>", 38 Utilities: "<a:utilites:897233087941988392>", 39 }; 40 const directories = [ 41 ...new Set(client.slashCommands.map(cmd => cmd.directory)), 42 ]; 43 const categories = directories.map(dir => { 44 if (dir == "Owner") return; 45 const getCmds = client.slashCommands 46 .filter(c => c.directory == dir) 47 .map(cmd => { 48 return { 49 name: cmd.name || "No command name", 50 }; 51 }); 52 return { 53 directory: dir, 54 commands: getCmds, 55 }; 56 }); 57 const embed = new EmbedBuilder() 58 .setTitle(`**NYX's Commands**`) 59 .setDescription(`Please choose a category in the dropdown menu`) 60 .setColor(client.color) 61 .setTimestamp() 62 .addFields( 63 { 64 name: ":link: **Invite Me**", 65 value: `[Click Here](${utils.inviteLink(client.user.id)})`, 66 inline: true, 67 }, 68 { 69 name: "<:support1:867093614403256350> **Need Help ?**", 70 value: `[Support Server](${client.invite})`, 71 inline: true, 72 }, 73 { 74 name: "<:YouTube:841186450497339412> **Video Guide**", 75 value: `[How to use Slash Coammands](https://youtu.be/YSKDu1gKntY)`, 76 inline: true, 77 }, 78 { 79 name: `<:nyx_description:897379659665264650> Documentation`, 80 value: `[Click here](${client.docs})`, 81 inline: true, 82 }, 83 { 84 name: "<a:booster:896527475063025704> **Premium**", 85 value: `You can either boost support server or subscribe to developer's team [Ko-Fi](https://ko-fi.com/cathteam) or gift a nitro to one of the developer team.`, 86 inline: false, 87 } 88 ) 89 .setURL(client.docs) 90 .setThumbnail( 91 "https://media.discordapp.net/attachments/896078559293104128/896392631565828146/nyx_logo_transparent.webp" 92 ) 93 .setFooter({ 94 text: `Requested by ${interaction.user.tag}`, 95 iconURL: interaction.user.displayAvatarURL({ dynamic: true }), 96 }); 97 const components = state => [ 98 new ActionRowBuilder().addComponents( 99 new StringSelectMenuBuilder() 100 .setCustomId("help-menu") 101 .setPlaceholder(`Please select a category`) 102 .setDisabled(state) 103 .addOptions( 104 categories.map(cmd => { 105 return { 106 label: cmd.directory, 107 value: cmd.directory, 108 description: `Commands from ${cmd.directory} category`, 109 emoji: emoji[cmd.directory] || null, 110 }; 111 }) 112 ) 113 ), 114 ]; 115 116 const msg = await interaction.channel.send({ 117 embeds: [embed], 118 components: components(false), 119 }); 120 const filter = m => m.user.id === interaction.user.id; 121 const collector = interaction.channel.createMessageComponentCollector({ 122 filter, 123 componentType: ComponentType.StringSelect, 124 time: 60000, 125 }); 126 collector.on("collect", async interaction => { 127 const [directory] = interaction.values; 128 const category = categories.find(u => u.directory === directory); 129 const newembed = new EmbedBuilder() 130 .setTitle( 131 `${emoji[directory]} ${directory} Commands ${emoji[directory]}` 132 ) 133 .setTimestamp() 134 .setColor(client.color) 135 .setFooter({ 136 text: `Please use /help (Command Name) for more details`, 137 }) 138 .setDescription( 139 category.commands 140 .map(cmd => { 141 return [`\`${cmd.name}\``]; 142 }) 143 .join(", ") 144 ); 145 interaction.reply({ embeds: [newembed] }); 146 }); 147 collector.on("end", () => msg.edit({ components: components(true) })); 148 } else { 149 const command = client.slashCommands.get(args[0].toLowerCase()); 150 if (!command) { 151 interaction.editReply({ 152 content: `There isn't any command named "${args[0]}"`, 153 }); 154 } else { 155 if (command.UserPerms && Array.isArray(command.UserPerms)) { 156 UserPermissions = command.UserPerms; 157 } else { 158 UserPermissions = [command.UserPerms ? command.UserPerms : ""]; 159 } 160 const fields = []; 161 const embed = new EmbedBuilder() 162 .setTitle(`"${command.name}" command details`) 163 .addFields([ 164 { 165 name: "**Command**:", 166 value: command.name ? `\`${command.name}\`` : "N/A", 167 }, 168 ]); 169 if (command.usage) 170 fields.push({ 171 name: "**Usage**:", 172 value: `\`/${command.name} ${command.usage}\``, 173 }); 174 else 175 fields.push({ 176 name: "**Usage**:", 177 value: `\`/${command.name}\``, 178 }); 179 180 if (command.description) 181 fields.push({ 182 name: "**Description**:", 183 value: command.description, 184 }); 185 186 if (command.timeout) 187 fields.push({ 188 name: "**Cooldown**:", 189 value: utils.timer(command.timeout), 190 }); 191 embed 192 .setFooter({ 193 text: `Requested by ${interaction.user.tag}`, 194 iconURL: interaction.user.displayAvatarURL({ dynamic: true }), 195 }) 196 .setTimestamp() 197 .addFields(fields) 198 .setURL(client.web) 199 .setColor(client.color); 200 interaction.followUp({ embeds: [embed] }); 201 } 202 } 203 }, 204 };