SWAGcommands
API reference

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.

FieldMeaning
clientYour discord.js Client
instanceThe current SWAGcommands instance
userInvoking Discord user
guild, member, channelAvailable Discord context; may be absent
messagePresent for a message invocation
interactionPresent for slash or context-menu invocation
argsNormalized string arguments
textJoined 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.