SWAGcommands
Commands

Slash commands

Define chat-input commands and Discord options.

Slash commands are the friendly entry point: users see them in Discord's picker, along with your descriptions and options. Put a file in commandsDir and set type: CommandType.SLASH.

src/commands/greet.ts
import { ApplicationCommandOptionType } from "discord.js";
import { CommandType } from "swagcommands";
import type { CommandObject } from "swagcommands";

const greet = {
  type: CommandType.SLASH,
  description: "Say hello to someone",
  options: [
    {
      name: "person",
      description: "Who gets the hello?",
      type: ApplicationCommandOptionType.User,
      required: true,
    },
  ],
  callback: ({ interaction }) => {
    const person = interaction.options.getUser("person", true);
    return `Hey, ${person}!`;
  },
} satisfies CommandObject;

export default greet;

The filename supplies greet; the description and options go into Discord's application-command manifest. Use discord.js's ApplicationCommandOptionType and option objects. Read the interaction in your callback when you need typed option values. usage.args is also available as normalized strings, but interaction.options.getUser() is a better fit for a Discord user option.

Deployment is explicit

After logging in and waiting until client.isReady(), run await swag.deployCommands(). Local file loading alone won't make /greet appear in Discord. See Deployment before using a bot that shares its command scope with another script.

Command settings

Slash definitions support deferReply, guildOnly, ownerOnly, testOnly, permissions, preconditions, init, and argument metadata. aliases and reply are message-side settings; they don't create extra slash commands. For an interaction that might take a while, use deferred responses.

On this page