Callback usage
The data passed to command callbacks.
Command callbacks receive one usage object. The exact type depends on the flow: MessageCommandUsage, ChatInputCommandUsage, SubcommandUsage, or a context-menu usage type. CommandType.BOTH receives a union, so check interaction or message before using either.
| Field | Meaning |
|---|---|
client | Your discord.js Client |
instance | The current SWAGcommands instance |
user | Invoking Discord user |
guild, member, channel | Available Discord context; may be absent |
message | Present for a message invocation |
interaction | Present for slash or context-menu invocation |
args | Normalized string arguments |
text | Joined argument text |
Subcommand usage additionally has commandName, subcommandName, and sometimes subcommandGroup. User context menus expose targetUser and targetMember; message context menus expose targetMessage. For typed Discord option values, use interaction.options in slash callbacks rather than relying on args.
import { CommandType } from "swagcommands";
import type { CommandObject } from "swagcommands";
const whoami = {
type: CommandType.BOTH,
description: "Show who's asking",
callback: ({ user, interaction, message }) => {
if (interaction) return `Slash request from ${user.username}`;
return `Message from ${message.author.username}`;
},
} satisfies CommandObject;For context menus, use the dedicated UserContextMenuCommandUsage or MessageContextMenuCommandUsage types when writing helpers. For a subcommand leaf, use SubcommandUsage. The root callback does not exist; only leaves execute.