What does this even mean

No description
14 Replies
untitled.
untitled.4mo ago
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();
});
}
}
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
Favna
Favna4mo ago
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) => {
return builder.setName('help')
});
}
public override registerApplicationCommands(registry: Command.Registry) {
registry.registerChatInputCommand((builder) =>
builder.setName('help')
);
}
public override registerApplicationCommands(registry: Command.Registry) {
registry.registerChatInputCommand((builder) =>
builder.setName('help')
);
}
MDN Web Docs
Arrow function expressions - JavaScript | MDN
An arrow function expression is a compact alternative to a traditional function expression, with some semantic differences and deliberate limitations in usage:
Favna
Favna4mo ago
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 /
untitled.
untitled.4mo ago
the dude im coding this for wants
Favna
Favna4mo ago
alright :monkashrug:
untitled.
untitled.4mo ago
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 @Boomeravna also how can i make my code register the slash command only in a single guild
Favna
Favna4mo ago
I literally told you. Your syntax is wrong right now. please read my message again
untitled.
untitled.4mo ago
i have fixed it.
No description
untitled.
untitled.4mo ago
IT IS RETURNING sorry caps
Favna
Favna4mo ago
Sapphire Framework
Registering Chat Input Commands | Sapphire
To register a Chat Input Command (also known as a Slash Command) with Discord, you need to acquire an application
untitled.
untitled.4mo ago
It is returning the name which is string isn't it
No description
No description
untitled.
untitled.4mo ago
now it registered this shit twice
No description
Favna
Favna4mo ago
you didnt have that return keyword before
No description
Want results from more Discord servers?
Add your server