Command definitions
The public fields for commands, leaves, and context menus.
Normal command files default-export a CommandObject: one of LegacyCommandObject, SlashCommandObject, or BothCommandObject. The type discriminates the callback usage. Use satisfies CommandObject so TypeScript checks your definition without widening all its properties.
| Field | Applies to | Purpose |
|---|---|---|
type | Normal and root | CommandType.LEGACY, .SLASH, or .BOTH |
callback | Normal and leaf | Work to run; return a response or undefined |
description | Slash-capable normal/root/leaf | Text shown by Discord; required for those shapes |
options | Normal and leaf | discord.js application command options |
autocomplete | Normal and leaf | Returns suggested strings for a focused option |
aliases | Message-capable normal/root/leaf | Alternative message names |
reply | Message-capable normal/root/leaf | Use message.reply() instead of channel send |
deferReply | Interaction-capable definitions | Boolean or { ephemeral?: boolean } |
init | All command definitions | Async setup during local file loading |
preconditions | All command definitions | Explicit guard list |
guildOnly, ownerOnly, testOnly | All command definitions | Common guard flags |
permissions | All command definitions | Required Discord permission bitfields |
minArgs, maxArgs, expectedArgs | Normal/root/leaf | Argument count and syntax hint; expectedArgs can derive string options for a normal slash command |
correctSyntax | Normal/root/leaf | Accepted field; the current runtime does not interpret it |
Subcommand roots use SubcommandObject and have no callback. Their files are named index. Leaves use SubcommandOptionObject. For slash-capable trees, both root and leaf need descriptions; leaf response settings override root settings. A context-menu file uses UserContextMenuCommandObject or MessageContextMenuCommandObject with ApplicationCommandType.User or .Message. Context menus have no options, aliases, or argument-count metadata.
The normal command callback can return a string or the relevant discord.js payload/options. Responses explains how each flow sends it. Usage objects lists what the callback receives.