SWAGcommands
API reference

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.

FieldApplies toPurpose
typeNormal and rootCommandType.LEGACY, .SLASH, or .BOTH
callbackNormal and leafWork to run; return a response or undefined
descriptionSlash-capable normal/root/leafText shown by Discord; required for those shapes
optionsNormal and leafdiscord.js application command options
autocompleteNormal and leafReturns suggested strings for a focused option
aliasesMessage-capable normal/root/leafAlternative message names
replyMessage-capable normal/root/leafUse message.reply() instead of channel send
deferReplyInteraction-capable definitionsBoolean or { ephemeral?: boolean }
initAll command definitionsAsync setup during local file loading
preconditionsAll command definitionsExplicit guard list
guildOnly, ownerOnly, testOnlyAll command definitionsCommon guard flags
permissionsAll command definitionsRequired Discord permission bitfields
minArgs, maxArgs, expectedArgsNormal/root/leafArgument count and syntax hint; expectedArgs can derive string options for a normal slash command
correctSyntaxNormal/root/leafAccepted 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.