const { EmbedBuilder, ChatInputCommandInteraction, ActionRowBuilder, StringSelectMenuBuilder, ComponentType, } = require("discord.js"); const Bot = require("../../Structures/Bot"); const fs = require("fs"); module.exports = { name: "help", description: "Get help with the bot", userperms: "", //HAS TO BE KickMembers or similar mode: { developerOnly: false, ownerGuildOnly: false, }, category: "General", example: ["/help"], options: [], /** * * @param {Bot} client * @param {ChatInputCommandInteraction} interaction * */ async run(client, interaction) { const emojis = { moderation: "🔨", general: "📋", lock: "🔒", }; function getCommand(name) { const getCommandID = client.application.commands.cache .filter((cmd) => cmd.name === name) .map((cmd) => cmd.id); return getCommandID; } const directories = [...new Set(client.commands.map((cmd) => cmd.folder))]; const formatString = (str) => `${str[0].toUpperCase()}${str.slice(1).toLowerCase()}`; const categories = directories.map((dir) => { const getCommands = client.commands .filter((cmd) => cmd.folder === dir) .map((cmd) => { return { name: cmd.name, description: cmd.description || "No command description", }; }); return { directory: formatString(dir), commands: getCommands, }; }); const embed = new EmbedBuilder() .setTitle("Help Menu") .setAuthor({ name: `${client.user.displayName}`, iconURL: `${client.user.displayAvatarURL()}`, }) .setDescription( `Use the dropdown to select a category.\n**Total Commands:** \`${client.commands.size}\`` ) .setColor("Blurple") .setTimestamp(); const components = (state) => [ new ActionRowBuilder().addComponents( new StringSelectMenuBuilder() .setCustomId("help-menu") .setPlaceholder("Find a category") .setDisabled(state) .addOptions( categories.map((cmd) => { return { label: cmd.directory, value: cmd.directory.toLowerCase(), description: `Commands from ${cmd.directory} category`, emoji: emojis[cmd.directory.toLowerCase() || "❔"], }; }) ) ), ]; const initialMessage = await interaction.reply({ embeds: [embed], components: components(false), }); const filter = (interaction) => interaction.user.id === interaction.member.id; const collector = interaction.channel.createMessageComponentCollector({ filter, componentType: ComponentType.StringSelect, time: 30000, }); collector.on("collect", (interaction) => { const [directory] = interaction.values; const category = categories.find( (x) => x.directory.toLowerCase() === directory ); const categoryEmbed = new EmbedBuilder() .setTitle( `${emojis[directory.toLowerCase()] || null} | ${formatString( directory )} Commands` ) .setDescription(`A list of commands in the ${directory} category`) .setColor("Blurple") .addFields( category.commands.map((cmd) => { return { name: ``, value: `\`${cmd.description}\``, }; }) ); interaction.update({ embeds: [categoryEmbed] }); }); collector.on("end", () => { initialMessage.edit({ components: components(true) }); }); }, };