Command types
Choose slash, message, both, subcommands, or a context menu.
There isn't one correct shape for every bot. SWAGcommands gives you a few ways in, and the type value says where a normal command can run.
| Type | Message prefix | Slash command | Needs deployment |
|---|---|---|---|
CommandType.SLASH | No | Yes | Yes |
CommandType.LEGACY | Yes | No | No |
CommandType.BOTH | Yes | Yes | For the slash side |
“Legacy” is the enum name for a message command, not a version of these docs. A normal command is a default-exported object in commandsDir; its filename becomes the name. Add description for slash-capable commands.
import { CommandType } from "swagcommands";
import type { CommandObject } from "swagcommands";
const ping = {
type: CommandType.SLASH,
description: "See if I'm awake",
callback: () => "Pong!",
} satisfies CommandObject;
export default ping;Slash commands
Discord's command picker, typed options, and autocomplete.
Message commands
Prefixes, aliases, and plain text arguments.
Both flows
One callback reachable by slash and message.
Subcommands
A root with individually configured leaves.
Context menus
Right-click a user or message.
Before the callback runs
SWAGcommands resolves preconditions during loading. At invocation time it checks them, commits any stateful checks (such as cooldowns), optionally defers the response, calls your callback, and sends the value you return. You can return undefined when you already replied yourself.
A command's init(client, instance) runs while definitions load. It is handy for command-specific setup; if it throws, initialization fails. For periodic work or cleanup, use a feature.