#What does this even mean

1 messages · Page 1 of 1 (latest)

slim bloom
next matrixBOT
#

To help others find answers, you can mark your question as solved via Right click solution message -> Apps -> ✅ Mark Solution

slim bloom
#
import { Command, CommandOptions } from '@sapphire/framework';
import { CommandInteraction, EmbedBuilder, ActionRowBuilder, StringSelectMenuBuilder, MessageComponentInteraction, ComponentType } from 'discord.js';
import { SlashCommandBuilder } from '@discordjs/builders';

export class HelpCommand extends Command {
    public constructor(context: Command.LoaderContext, options: CommandOptions) {
        super(context, {
            ...options
        });
    }

    public override registerApplicationCommands(registry: Command.Registry) {
        registry.registerChatInputCommand((builder) => {
            builder.setName('help')
        });
    }

    public async chatInputRun(interaction: CommandInteraction) {
        const cmds = this.container.stores.get('commands');
        const categories = new Map<string, Command[]>();

        cmds.forEach(cmd => {
            const category: string = (cmd as any).category || 'Uncategorized';
            const list = categories.get(category) || [];
            list.push(cmd);
            categories.set(category, list);
        });

        const selectMenu = new StringSelectMenuBuilder()
            .setCustomId('select-help')
            .setPlaceholder('Choose a category')
            .addOptions(
                Array.from(categories.keys()).map(category => ({
                    label: category,
                    description: `Commands from the ${category} category`,
                    value: category
                }))
            );

        const row = new ActionRowBuilder<StringSelectMenuBuilder>().addComponents(selectMenu);
        const emb = new EmbedBuilder()
            .setDescription("Choose a category from the list.");

        await interaction.reply({
            components: [row],
            embeds: [emb],
            ephemeral: true
        });

        const filter = (i: MessageComponentInteraction) =>
            i.isStringSelectMenu() &&
            i.customId === 'select-help' &&
            i.user.id === interaction.user.id;

        const collector = interaction.channel?.createMessageComponentCollector({
            filter,
            componentType: ComponentType.StringSelect,
            time: 60000
        });

        collector?.on('collect', async (i: MessageComponentInteraction) => {
            if (!i.isStringSelectMenu()) return;

            const selectedCategory = i.values[0];
            const commands = categories.get(selectedCategory);
            if (commands) {
                const embed = new EmbedBuilder()
                    .setTimestamp()
                    .setTitle(`Help - ${selectedCategory}`)
                    .setDescription(`<> - required argument\n[] - optional argument`)
                    .setFooter({ text: `Requested by ${interaction.user.username}`, iconURL: interaction.user.displayAvatarURL() })
                    .setColor(0x0099ff);

                commands.forEach(cmd => {
                    embed.addFields({ name: `\`>\` ${cmd.name}`, value: cmd.description || 'No description' });
                });

                await i.update({ embeds: [embed], components: [row] });
            }
        });

        collector?.on('end', () => {
            interaction.deleteReply();
        });
    }
}
#

heres the code

slate summit
# slim bloom ```ts import { Command, CommandOptions } from '@sapphire/framework'; import { Co...

Please review how JavaScript arrow functions work: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/Arrow_functions

Currently your registerChatInputCommand method isn't returning anything so the error is that you're providing undefined where string was expected, which is for name because you're not actually setting it. You need to either remove the wrapping { } or add a return keyword.

One of these 2:

public override registerApplicationCommands(registry: Command.Registry) {
    registry.registerChatInputCommand((builder) => {
        return builder.setName('help')
    });
}
public override registerApplicationCommands(registry: Command.Registry) {
    registry.registerChatInputCommand((builder) =>
        builder.setName('help')
    );
}
MDN Web Docs

An arrow function expression is a compact alternative to a traditional function expression, with some semantic differences and deliberate limitations in usage:

#

Sidenote that you really dont need a help command when using slash commands btw because the list of commands is integrated in the Discord client when the user types a single /

slim bloom
#

the dude im coding this for wants

slate summit
#

alright monkashrug

slim bloom
#

i took my messaage command i made for this and used chatgpt to convert it to a slash command

#

@slate summit also how can i make my code register the slash command only in a single guild

slate summit
#

please read my message again

slim bloom
#

i have fixed it.

#

IT IS RETURNING

#

sorry caps

slim bloom
#

now it registered this shit twice

slate summit