#What does this even mean
1 messages · Page 1 of 1 (latest)
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
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')
);
}
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 /
the dude im coding this for wants
alright 
wait what's wrong with my arrow function
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
I literally told you. Your syntax is wrong right now.
please read my message again
It is returning the name which is string isn't it
now it registered this shit twice
you didnt have that return keyword before