Instance API
The methods and state available after SWAG.create().
Keep the value returned by SWAG.create(): it is your handle for deployment, features, stores, and the loaded command list.
| Member | What it does |
|---|---|
state | "idle", "initializing", "ready", "failed", or "destroyed" |
isReady() | Whether local initialization finished successfully |
client | The supplied discord.js client |
defaultPrefix | Configured fallback prefix |
testServers, botOwners | Configured ID arrays |
prefixStore, cooldownStore | Active storage implementations |
preconditions | Loaded PreconditionStore |
listCommands() | Snapshot of loaded command metadata |
deployCommands(options?) | Sync application commands to Discord |
clearCommands(target) | Clear one global or guild target |
startFeatures() | Run client-ready feature phase |
stopFeatures() | Stop timers and run cleanup |
The instance also exposes commandHandler, subcommandHandler, contextMenuCommandHandler, eventHandler, messageCommandRouter, responseHandler, and validations. Handlers for optional directories may be undefined. Most bots only need the methods above.
Inspect loaded commands
for (const entry of swag.listCommands()) {
console.log(entry.kind, entry.name, entry.type);
if (entry.kind === "subcommand") {
console.log(entry.subcommands.map((leaf) => leaf.name));
}
}Entries are sorted by name. Normal aliases do not create duplicate entries; user and message context menus with the same name are separate entries because their types differ. Returned entries and alias arrays are copies, so changing them won't edit the command registry.
Deployment calls
await swag.deployCommands();
await swag.deployCommands({ scope: "global" });
await swag.deployCommands({ scope: "test", testGuildIds: ["GUILD_ID"] });
await swag.clearCommands({ scope: "global" });
await swag.clearCommands({ scope: "guild", guildId: "GUILD_ID" });Deployment requires a ready Discord client. See Deployment for replacement semantics and failure behavior.