Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const { EmbedBuilder, ActionRowBuilder, SelectMenuBuilder } = require("discord.js");
- module.exports = {
- name: "help",
- category: "General",
- description: "The Help Menu that shows all the available commands.",
- type: 1,
- options: [],
- async execute(XyroClient, interaction) {
- let dirs = [];
- let categories = [];
- let page = 0;
- const menuOpts = [
- {
- label: `Home`,
- description: `Home Page`,
- emoji: "🏡",
- value: `home`,
- }
- ]
- const emojis = {
- General: "📘",
- Fun: "🎉",
- Economy: "💵"
- }
- const description = {
- General: "Where all the General Commands are stored",
- Fun: "Where all the Fun Comamnds are stored",
- Economy: "Where all the Economy Commands are stored"
- }
- //const editedRow = new ActionRowBuilder()
- fs.readdirSync('./src/commands/').forEach((dir) => {
- const commands = fs.readdirSync('./src/commands/' + dir).filter(file => file.endsWith(".js"));
- const cmds = commands.map((cmd) => {
- let file = require(`../../commands/${dir}/${cmd}`);
- return {
- name: dir,
- commands: {
- name: file.name,
- category: file.category,
- description: file.description
- }
- }
- })
- categories.push(cmds.filter(cat => cat.name === dir));
- })
- categories.forEach((cat) => {
- dirs.push(cat[0].name);
- });
- dirs.forEach((dir) => {
- menuOpts.push(
- {
- label: `${dir}`,
- description: `${dir} comamnds page`,
- emoji: `${emojis[dir] || ''}`,
- value: `${page++}`,
- }
- )
- })
- let menu = new SelectMenuBuilder()
- .setCustomId('help_menu')
- .setPlaceholder('Select a Category')
- .addOptions(menuOpts)
- .setDisabled(false)
- var row = new ActionRowBuilder()
- .addComponents(menu);
- const helpMenuEmbed = new EmbedBuilder()
- .setColor(0xb5c0ff)
- .setTitle(`${XyroClient.user.username}'s Help Menu 📚`)
- .setDescription(`Hi! Im a multipurpose bot with many functions. If you ever need my prefix, my prefix is \`${prefix}\``);
- let msg = await interaction.reply({ embeds: [helpMenuEmbed], components: [row] });
- const filter = i => !i.user.bot;
- const collector = message.channel.createMessageComponentCollector({
- filter,
- componentType: ComponentType.SelectMenu,
- time: 20000
- });
- collector.on('collect', async (i) => {
- const value = i.values[0];
- if (i.user.id !== message.author.id) return;
- if (i.customId !== 'help_menu') return;
- i.deferUpdate();
- if (value && value !== 'home') {
- helpMenuEmbed.setFields();
- helpMenuEmbed.setDescription('\u200B')
- helpMenuEmbed.setTitle(`${emojis[categories[value][0].name] ? emojis[categories[value][0].name] : ""} Help Menu | ${categories[value][0].name}`)
- categories[value].forEach((cmd) => {
- helpMenuEmbed.addFields(
- { name: `\`${prefix}${cmd.commands.name || ''}\``, value: `${cmd.commands.description || 'No Description Set'}\n${cmd.commands.category}`, inline: true }
- )
- })
- }
- msg = await i.edit({ embeds: [helpMenuEmbed], components: [row] });
- if (value === 'home') {
- helpMenuEmbed.setFields()
- .setDescription(`Hi! Im a multipurpose bot with many functions. If you ever need my prefix, my prefix is \`${prefix}\``);
- helpMenuEmbed.setTitle(`${XyroClient.user.username}'s Help Menu`)
- dirs.forEach((dir) => {
- helpMenuEmbed.addFields(
- {
- name: `${emojis[dir] || ''} ${dir.charAt(0).toUpperCase() + dir.slice(1).toLowerCase()}`,
- value: `${description[dir] ? description[dir] : `${dir.charAt(0).toUpperCase() + dir.slice(1).toLowerCase()} Commands`}`,
- inline: false
- }
- )
- })
- }
- msg = await i.edit({ embeds: [helpMenuEmbed], components: [row] });
- })
- collector.on('end', async (i) => {
- menu.setDisabled(true)
- row = new ActionRowBuilder().addComponents(menu)
- await i.edit({ embeds: [helpMenuEmbed], components: [editedRow] });
- await Logger.success("Disabled Select Menu");
- })
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment