SWAGcommands
Guides

Prefixes

Set a default prefix and customize it per guild.

Message commands start with a prefix. The default is !, configurable when you create the instance:

const swag = await SWAG.create({
  client,
  commandsDir: "./dist/commands",
  defaultPrefix: "?",
});

A guild can have its own prefix. SWAGcommands asks a PrefixStore for that guild's value and falls back to defaultPrefix when there isn't one. DMs always use the default. MemoryPrefixStore is provided out of the box; it is process-local and resets on restart.

const prefixHandler = swag.commandHandler?.prefixHandler;
await prefixHandler?.set("YOUR_GUILD_ID", "~");
console.log(await prefixHandler?.get("YOUR_GUILD_ID")); // "~"

If you don't configure commandsDir, there is no normal command handler. You can also call the injected store directly. To persist prefixes, implement PrefixStore and pass it to SWAG.create({ prefixStore }):

import type { PrefixStore } from "swagcommands";

class DatabasePrefixStore implements PrefixStore {
  async getPrefix(guildId: string) {
    return database.getPrefix(guildId); // string | undefined
  }

  async setPrefix(guildId: string, prefix: string) {
    await database.setPrefix(guildId, prefix);
  }
}

database here is your application code. The interface supports sync or async methods. Avoid an empty prefix unless you genuinely want every human message to be considered as a possible command. The message command guide covers parsing and required Discord intents.