const { SlashCommandBuilder, ComponentType, EmbedBuilder, ActionRowBuilder, StringSelectMenuBuilder, } = require("discord.js"); module.exports = { data: new SlashCommandBuilder() .setName("komandos") .setDescription("Parodo komandas iš tam tikros kategorijos.") .setDMPermission(false), async execute(interaction) { const { client, channel } = interaction; const emojis = { bendras: "🌐", linksmi: "🕹️", moderacija: "👮", sistemos: "⚙️", developer: "🧑‍💻", }; 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.data.name, description: cmd.data.description || "Nėra aprašymo šiai komandai.", }; }); return { directory: formatString(dir), commands: getCommands, }; }); const embed = new EmbedBuilder() .setDescription( "Komandų sąrašus pamatykite pasirinkę kategoriją esančią žemiau!" ) .setColor("Red") .setAuthor({ name: `${client.user.username} Komandos`, iconURL: client.user.avatarURL(), }); const components = (state) => [ new ActionRowBuilder().addComponents( new StringSelectMenuBuilder() .setCustomId("help-menu") .setPlaceholder("Ieškoti kategorijos") .setDisabled(state) .addOptions( categories.map((cmd) => { return { label: cmd.directory, value: cmd.directory.toLowerCase(), description: `Komandos iš ${cmd.directory} kategorijos.`, emoji: emojis[cmd.directory.toLowerCase() || null], }; }) ) ), ]; const initialMessage = await interaction.reply({ embeds: [embed], components: components(false), }); const filter = (interaction) => interaction.user.id === interaction.member.id; const collector = channel.createMessageComponentCollector({ filter, componentType: ComponentType.StringSelect, }); collector.on("collect", (interaction) => { const [directory] = interaction.value; const category = categories.find( (x) => x.directory.toLowerCase() === directory ); const categoryEmbed = new EmbedBuilder() .setTitle( `${emojis[directory.toLowerCase()] || null} ${formatString( directory )} komandos` ) .setDescription(`Visų komandų sąrašas ${directory} kategorijoje.`) .setColor("Red") .addFields( category.commands.map((cmd) => { return { name: ``, value: `\`${cmd.description}\``, inline: true, }; }) ); interaction.update({ embeds: [categoryEmbed] }); }); collector.on("end", () => { initialMessage.edit({ components: components(true) }); }); }, };