Skip to content
Spraxium

Primary navigation

Publishing Slash Commands

Choose where slash commands appear and compose the selection with folders and command classes.

Choose a default destination

A command that omits a scope is normally published globally to every server where the app is installed. Set slash.guilds for an internal bot or a bot used to test commands in a known set of servers. Guild commands usually appear quickly and are useful when you want to try changes in one server before a public rollout.

spraxium.config.ts
import { defineConfig } from '@spraxium/core';

export default defineConfig({
  slash: {
    guilds: '123456789012345678',
  },
});

The guilds field accepts one Discord server ID as a string, a comma-separated string or an array of IDs. Use an array when you want to see several fixed IDs on separate lines. Omit the field to publish globally by default. Repeated IDs are rejected.

spraxium.config.ts
import { defineConfig } from '@spraxium/core';

export default defineConfig({
  slash: {
    guilds: ['123456789012345678', '223456789012345678'],
  },
});

Use an environment variable

Pass the variable directly to guilds. Use one server ID or several separated by commas. Spraxium removes spaces around IDs and applies the same validation as a literal config. Choose any environment variable name that suits your deployment. An unset variable uses global publication, just like omitting guilds. A variable set to an empty string is a configuration error.

spraxium.config.ts
import { defineConfig } from '@spraxium/core';

export default defineConfig({
  slash: {
    guilds: process.env.SLASH_GUILD_IDS,
  },
});
.env
SLASH_GUILD_IDS=123456789012345678,223456789012345678

Select by folder and by class

Use include to choose the commands to publish. A string selects registered command classes declared in a folder and its subfolders, relative to the project root. A class selects one registered command by identity. Use exclude to remove selections from the result. The class must still be listed in a module’s commands, and its handler must be registered normally. If your project only needs one or two exceptions, class selectors are usually enough. Omitting include selects all eligible commands. An empty include: [] selects none. If a command matches both lists, exclude takes precedence.

spraxium.config.ts
import { defineConfig } from '@spraxium/core';

import { PingCommand } from './src/commands/ping.command';
import { PreviewCommand } from './src/commands/preview.command';

export default defineConfig({
  slash: {
    guilds: [
      '123456789012345678',
      {
        id: '223456789012345678',
        include: ['src/commands/staff', PingCommand],
        exclude: [PreviewCommand],
      },
    ],

    include: ['src/commands/public', PingCommand],
  },
});

When to use the id field

Each item in guilds represents one server. The string "123456789012345678" is shorthand for { id: "123456789012345678" }. Use the object to give that server its own include or exclude. If the ID is already listed as a string, replace that entry with the object. List each server once.

A guild object uses id to choose the server. Its include replaces the shared include for that server. Its exclude adds to the shared exclusions. A guild listed as a string uses the shared rules. Here the first guild gets the public folder and PingCommand. The second gets the staff folder and PingCommand, with PreviewCommand removed.

The standard build and CLI launcher enable source maps for folder selection. If you build and start the bot yourself, enable source maps in both the bundler and the Node launcher with node --enable-source-maps.

Publish a folder to just one server

If the bot should publish only the commands in the admin folder to one server, pass the ID to guilds and the folder to the shared include. The selection also covers subfolders.

spraxium.config.ts
import { defineConfig } from '@spraxium/core';

export default defineConfig({
  slash: {
    guilds: '123456789012345678',

    include: ['src/commands/admin'],
  },
});

If the bot serves two guilds and only the first should receive the admin commands, add exclude to the second. The first gets all commands and the second gets the rest. To give the first guild only admin, declare it as an object with id and include: ["src/commands/admin"].

spraxium.config.ts
import { defineConfig } from '@spraxium/core';

export default defineConfig({
  slash: {
    guilds: [
      '123456789012345678',
      {
        id: '223456789012345678',
        exclude: ['src/commands/admin'],
      },
    ],
  },
});

These examples use the default destination for commands in the folder. If a command has an explicit guild or scope in its decorator, Spraxium uses that destination and applies its filters.

Override one command’s destination

Set scope: "global" in a decorator when one command must be global in an app whose default scope is guilds. Set guild to a single ID when the command belongs in just that server. The two properties are alternatives. The filters still apply to the destinations chosen by the decorator. Use guards and permissions to control who may execute a command that is visible in a server.

snippet.ts
@SlashCommand({
  name: 'help',
  description: 'Show available commands',
  scope: 'global',
})
export class HelpCommand {}

During startup, Spraxium builds a SlashPublicationPlan from the command classes and their destinations. It uses that map to publish the commands and find the handler in the scope where each command was registered.

Changing previously published scopes

Spraxium replaces the application commands for the destinations it manages in the current configuration. A configured guild with an empty result has its previous commands removed, except for context menus registered for that guild. When moving a bot from global commands to guild-only commands, the previous global route may need a one-time cleanup. This also applies to a guild ID you removed from the list. Context menus continue to use their own registration settings.

See slash command definitions