import * as DJS from 'discord.js'; import Client from '../../client'; import fs from 'fs'; import { useI18n } from '../../events/interactionCreate/executeCommands'; import Guild from '../../schemas/Guild'; import Embed from '../../utils/embed'; export const data = new DJS.SlashCommandBuilder() .setName('help') .setDescription('List of all bot commands.') export async function execute( client: Client, interaction: DJS.ChatInputCommandInteraction ) { const i18n = useI18n() const nowLang = await Guild.findOne({ guildId: interaction.guild?.id }); const commandFolders = fs.readdirSync('./src/commands').filter(folder => !folder.startsWith('.')); const commandCategory: any = {}; for (const folder of commandFolders) { const commandFiles = fs.readdirSync(`./src/commands/${folder}`).filter(file => file.endsWith('.ts')); const commands = []; for (const file of commandFiles) { const { default: command } = await import(`../${folder}/${file}`); commands.push({ name: command.data.name, description: command.data.description }); } commandCategory[folder] = commands } const dropdownOptions = Object.keys(commandCategory).map(folder => ({ label: folder, value: folder })); const selectMenu = new DJS.StringSelectMenuBuilder() .setCustomId('category-select') .setPlaceholder(`${i18n.twl(nowLang?.lang ?? "en", "help.placeholder")}`) .addOptions(...dropdownOptions.map(option => ({ label: option.label, value: option.value }))); const embed = new DJS.EmbedBuilder() .setTitle(`${i18n.twl(nowLang?.lang ?? "en", "help.menu")}`) .setColor('White') .setTimestamp() .setFooter({ text: `${client?.user?.username}`, iconURL: `${client?.user?.displayAvatarURL({ size: 32 })}` }) .setAuthor({ name: interaction.user?.username, iconURL: interaction.user?.displayAvatarURL({ size: 32 }), }) .setDescription(`${i18n.twl(nowLang?.lang ?? "en", "help.description")}`) const row: any = new DJS.ActionRowBuilder() .addComponents(selectMenu); await interaction.reply({ embeds: [embed], components: [row] }); const filter: any = (i: { isStringSelectMenu: () => DJS.StringSelectMenuInteraction; customId: string; }) => i.isStringSelectMenu() && i.customId === 'category-select'; const collector = interaction.channel?.createMessageComponentCollector({ filter: filter }); collector?.on('collect', async (i: DJS.StringSelectMenuInteraction) => { const selectedCategory = i.values[0]; const categoryCommands = commandCategory[selectedCategory]; const categoryEmbed = new DJS.EmbedBuilder() .setTitle(`${i18n.twl(nowLang?.lang ?? "en", "help.menu")}`) .setColor('White') .setTimestamp() .setFooter({ text: `${client?.user?.username}`, iconURL: `${client?.user?.displayAvatarURL({ size: 32 })}` }) .setAuthor({ name: interaction.user?.username, iconURL: interaction.user?.displayAvatarURL({ size: 32 }), }) .setDescription(`${i18n.twl(nowLang?.lang ?? "en", "help.description2")}`) .addFields(categoryCommands.map((command: { name: any; description: any; }) => ({ name: command.name, value: command.description }))) await i.update({ embeds: [categoryEmbed] }); }) }