SWAGcommands
API reference

Imports and TypeScript

Use the package root and get reliable types for definitions.

The supported import path is swagcommands. The package ships JavaScript and generated declarations together. Use root exports for the class, helpers, types, and error classes; deep imports into src or dist are outside the package's export map.

For TypeScript compiled to CommonJS with esModuleInterop:

import SWAG, { CommandType, Cooldown, FeaturePhase } from "swagcommands";
import type { CommandObject, Feature, Options } from "swagcommands";

The class is also a named export as SWAGCommands. Plain CommonJS JavaScript can use:

const { SWAGCommands: SWAG, CommandType } = require("swagcommands");

The package itself is CommonJS. In native Node ESM, the default import is the CommonJS export object; access its default property for the class:

import swagcommands from "swagcommands";
const SWAG = swagcommands.default;

Check definitions without widening them

import { CommandType } from "swagcommands";
import type { CommandObject } from "swagcommands";

const ping = {
  type: CommandType.SLASH,
  description: "Check the bot",
  callback: () => "Pong!",
} satisfies CommandObject;

export default ping;

Use SubcommandObject for a root, SubcommandOptionObject for a leaf, and the appropriate context-menu object type for a context menu. A feature uses Feature or FeatureFunction. Type imports keep the emitted JavaScript clean.

Custom precondition names can be typed with a factory or module augmentation of Preconditions; the custom preconditions guide shows both. The quick start includes a working CommonJS TypeScript configuration.

On this page