const { readdirSync } = require("fs"); const prefix = require("../../config.json").prefix; const { Message, Client, ButtonStyle, ActionRowBuilder, ButtonBuilder, EmbedBuilder, Util, SelectMenuBuilder, SelectMenuOptionBuilder, ComponentType, } = require("discord.js"); module.exports = { name: "help", aliases: ["bh"], description: "Shows all available bot commands.", /** * * @param {Client} client * @param {Message} message * @param {String[]} args */ run: async (client, message, args) => { if (!args[0]) { const directories = [ ...new Set(client.commands.map((cmd) => cmd.directory)), ]; const formatString = (str) => `${str[0].toUpperCase()}${str.slice(1).toLowerCase()}`; const categories = directories.map((dir) => { const getCommands = client.commands .filter((cmd) => cmd.directory === dir) .map((cmd) => { return { name: cmd.name || "No name", }; }); return { directory: formatString(dir), commands: getCommands, }; }); const embed = new EmbedBuilder() .setTitle("Command list") .setDescription( `**[Invite](https://voidbots.net/bot/880317355627016232/invite) | [Vote](https://voidbots.net/bot/880317355627016232/vote) | [Support Server](https://discord.gg/jGecsrxN3B)\n\nAvailable categories:\n\n ${directories.join( "\n" )}**` ) .setColor(Util.resolveColor("DarkPurple")); const row = new ActionRowBuilder().addComponents( new SelectMenuBuilder() .setCustomId("dropdown-help") .setPlaceholder("Choose a category") .addOptions( ...categories.map((cmd) => { return { label: cmd.directory, value: cmd.directory.toLocaleLowerCase(), description: `Commands from ${cmd.directory} category`, }; }) ) ); const row1 = new ActionRowBuilder().addComponents( new SelectMenuBuilder() .setCustomId("dropdown-helpp") .setPlaceholder("Interaction ended") .addOptions( ...categories.map((cmd) => { return { label: cmd.directory, value: cmd.directory.toLocaleLowerCase(), description: `Commands from ${cmd.directory} category`, }; }) ) .setDisabled(true) ); const initialMessage = await message.channel.send({ embeds: [embed], components: [row], }); const filter = async (interaction) => { await interaction.deferUpdate(); return interaction.user.id === message.author.id; }; const collector = message.channel.createMessageComponentCollector({ filter, componentType: ComponentType.SelectMenu, max: 15, time: 60000, }); collector.on("collect", (interaction) => { const [directory] = interaction.values; const category = categories.find( (x) => x.directory.toLowerCase() === directory ); const catEmbed = new EmbedBuilder().setDescription( `**List of commands from ${directory} category**\n\n\`\`\`fix\n${category.commands .map((cmd) => { return cmd.name; }) .join(", ")}\`\`\`` ).setColor(Util.resolveColor("DarkPurple")); initialMessage.edit({ embeds: [catEmbed], components: [row] }); }); collector.on("end", (interaction) => { initialMessage.edit({ components: [row1] }); }); } else { const command = client.commands.get(args[0].toLowerCase()) || client.commands.find( (c) => c.aliases && c.aliases.includes(args[0].toLowerCase()) ); try { const embed = new EmbedBuilder() .setColor(Util.resolveColor("DarkPurple")) .setTitle("Command Details:") .addFields({ name: "PREFIX:", value: `\`${prefix}\`` }) .addFields({ name: "COMMAND:", value: command.name ? `\`${command.name}\`` : "No name for this command.", }) .addFields({ name: "ALIASES:", value: command.aliases ? `\`${command.aliases.join("` `")}\`` : "No aliases for this command.", }) .addFields({ name: "USAGE:", value: command.usage ? `\`${prefix}${command.name} ${command.usage}\`` : `\`${prefix}${command.name}\``, }) .addFields({ name: "Description:", value: command.description ? command.description : "No description for this command.", }) .setTimestamp(); return message.channel.send({ embeds: [embed] }); } catch (e) { console.log(e); return message.channel.send(`\`\`\`js\n${e}\`\`\``); } } }, };