Adding a Slash Command
このコンテンツはまだ日本語訳がありません。
How to add a slash command. commandLoader.ts registers any .ts file under src/commands/ on the
next startup.
- Create the file:
src/commands/{command}.tsfor a root command,src/commands/{category}/{subcommand}.tsfor a subcommand,src/commands/{category}/{group}/{subcommand}.tsfor a subcommand in a group.
- Export
configureCommand(command)(root) orconfigureSubcommand(subcommand)(category) to declare the name, description, and options, andexecute(client, interaction, userData, locale)to handle it. - Build descriptions and options with
localizer("en-US", ...)so the loader registers every locale’s text. - Add the keys to
src/locales/en-US/commands/{category}.ts; other locales fall back to English. Option descriptions use{option_name}_descriptionand choice labels{choice_value}_option.{option_name}_optionfor a description silently falls back to English. - Acknowledge within Discord’s 3 seconds:
reply()right away for fast commands,deferReply()before the firstawaitfor slow ones. Do not defer before opening a modal or a pagination helper, which acknowledge the interaction themselves. See Command System.
To register a command only in some environments, export a gate. The loader still imports the file, so keep production-only side effects out of module scope:
export const isCommandEnabled = () => process.env.RUN_ENV === "production" && process.env.TOMORI_SUPPORTER_BILLING_ENABLED === "true";Before building, pick the command’s archetype (panel, wizard, direct family, immediate or destructive action) in Command Archetypes.
Naming
Section titled “Naming”Name commands with the words users see in Discord:
- Nouns for durable settings:
crosschannel-blocklist, notblock-crossmsg-channels. - No abbreviations such as
msgorcfgunless users already know them. - A command that edits a stored set is named after the set (
crosschannel-blocklist); do not split it intoaddandremovecommands.
Settings that are a set
Section titled “Settings that are a set”For a set of channels, roles, or notice types that users review as a whole, use one command that owns
the full set. /config > Channels > Channel Rules is the reference.
- The modal opens with the saved items already checked, and submitting writes the whole checked set.
- Up to 50 items fit one checkbox modal. Beyond that, show a page picker first, and preload each page’s modal with that page’s saved state.
- Show the saved state in
/statusso users can see it without reopening the command.
Verify
Section titled “Verify”bun run check-localesbun run checkbun run lintThen run the command in Discord: it appears, its options work, and it renders in another locale.