const { SlashCommandBuilder } = require("@discordjs/builders"); const { EmbedBuilder, ActionRowBuilder, SelectMenuBuilder, } = require("discord.js"); module.exports = { data: new SlashCommandBuilder() .setName("help") .setDescription("Get information about commands!") .addStringOption((option) => option .setName("command") .setDescription("Command you want to see information of.") .setRequired(false) ), async execute(interaction) { if (interaction.options.getString("command")) { let cmd = interaction.options.getString("command").toLowerCase(); const command = bot.commands.get(cmd) || bot.commands.find((a) => a.aliases && a.aliases.includes(cmd)); if (command && command.category !== "admin") { const embed = new EmbedBuilder() .setTitle(`${command.name.capitalizeFirst()} Command`) .setColor("AQUA") .setAuthor({ name: interaction.user.tag, iconURL: interaction.user.displayAvatarURL(), }) .setThumbnail(interaction.user.displayAvatarURL()) .setFooter({ text: "Usage Syntax: [optional]" }); command.description ? embed.addFields({ name: "Description", value: `\`${command.description}\``, }) : null; command.category ? embed.addFields({ name: "Category", value: `\`${command.category.capitalizeFirst()}\``, }) : null; command.usage ? embed.addFields({ name: "Usage", value: `\`${bot.prefix}${command.usage}\``, }) : null; command.aliases ? embed.addFields({ name: "Aliases", value: `\`${command.aliases.join(", ")}\``, }) : null; command.cooldown ? embed.addFields({ name: "Cooldown", value: `\`${command.cooldown}s\``, }) : null; embed.addFields({ name: "VIP", value: `\`${command.vip ? "True" : "False"}\``, }); return interaction.reply({ embeds: [embed], fetchReply: true }); } } const directories = [...new Set(bot.commands.map((cmd) => cmd.category))]; const formatString = (str) => `${str[0].toUpperCase()}${str.slice(1).toLowerCase()}`; const categories = directories.map((dir) => { const getCommands = bot.commands .filter((cmd) => cmd.category === dir) .map((cmd) => { return { name: cmd.name || "there is no name for this command", description: cmd.description || "there is no description for this command", admin: cmd.admin, }; }); return { directory: formatString(dir), commands: getCommands, }; }); const embed = new EmbedBuilder() .setTitle("Help Menu") .setColor("AQUA") .setAuthor({ name: interaction.user.tag, iconURL: interaction.user.displayAvatarURL(), }) .setThumbnail(interaction.user.displayAvatarURL()) .setDescription( `**Welcome ${interaction.user.tag} to our help menu** Please select a category of commands down below. If you want information about a specific command please use "${bot.prefix}help "` ) .addFields({ name: ":paperclips: Links", value: `${bot.emoji.invite} Invite: [Click Here](${bot.links.invite}) ${bot.emoji.discord} Support: [Click Here](${bot.links.support}) ${bot.emoji.invite} Top.GG: [Click Here](${bot.links.topgg}) ${bot.emoji.invite} DBL.com: [Click Here](${bot.links.vote})`, }) .setFooter({ text: interaction.guild.name }) .setTimestamp(); let map = categories.map((cmd) => { return { label: cmd.directory, value: cmd.directory.toLowerCase(), }; }); let selectmenu = new SelectMenuBuilder() .setCustomId("help-menu") .setPlaceholder("Please select a category") .addOptions({ label: "All", value: "all" }); for (var v of map) { if (v.label === "Admin") continue; else selectmenu.addOptions(v); } const components = (state) => [ new ActionRowBuilder().addComponents(selectmenu.setDisabled(state)), ]; const initialMessage = await interaction.reply({ embeds: [embed], components: components(false), fetchReply: true, }); const filter = (intc) => intc.customId === "help-menu" && intc.user.id === interaction.user.id; const collector = initialMessage.createMessageComponentCollector({ filter, componentType: "SELECT_MENU", time: 122e3, }); let timeout = setTimeout(() => { collector.stop(); }, 15e3); collector.on("collect", (interaction) => { console.log(interaction) clearTimeout(timeout); timeout = null; timeout = setTimeout(() => { collector.stop(); }, 15e3); const [directory] = interaction.values; let category; let categoryCommands; if (directory === "all") { category = { directory: "All" }; categoryCommands = bot.commands .filter((cmd) => cmd.category !== "admin") .filter((cmd) => cmd.category !== "nsfw") .map((cmd) => { return `\`${cmd.name}\``; }) .sort(); } else { category = categories.find( (x) => x.directory.toLowerCase() === directory ); categoryCommands = category.commands.map((cmd) => { return `\`${cmd.name}\``; }); } const categoryEmbed = new EmbedBuilder() .setTitle( `${category.directory} Commands (${ directory === "all" ? bot.commands .filter((cmd) => cmd.category !== "admin") .filter((cmd) => cmd.category !== "nsfw").size : bot.commands.filter((cmd) => cmd.category === directory).size })` ) .setDescription("> " + categoryCommands.join(", ")) .addFields({ name: ":paperclips: Links", value: `${bot.emoji.invite} Invite: [Click Here](${bot.links.invite}) ${bot.emoji.discord} Support: [Click Here](${bot.links.support}) ${bot.emoji.invite} Top.GG: [Click Here](${bot.links.topgg}) ${bot.emoji.invite} DBL.com: [Click Here](${bot.links.vote})`, }) .setAuthor({ name: interaction.user.tag, iconURL: interaction.user.displayAvatarURL(), }) .setThumbnail(interaction.user.displayAvatarURL()) .setColor("Aqua") .setFooter({ text: `Use ${bot.prefix}help to get info about specific commands.`, }); interaction.reply({ embeds: [categoryEmbed] }); }); collector.on("end", () => { if (initialMessage) try { initialMessage.edit({ components: components(true) }); } catch (e) { if (e) return; } }); }, };