Skip to content

Slash Commands

Slash commands are Bight’s primary interface. Each .ts file in src/commands/ is automatically discovered and registered on boot.

src/commands/ping.ts
import { MessageFlags, SlashCommandBuilder } from "discord.js";
import { defineCommand } from "@bight-ts/core";
export default defineCommand({
data: new SlashCommandBuilder()
.setName("ping")
.setDescription("Reply with pong."),
async execute({ interaction }) {
await interaction.reply({
content: "Pong.",
flags: MessageFlags.Ephemeral,
});
},
});

defineCommand accepts standard Discord.js builders. There’s no Bight-specific DSL for command metadata.

For commands with subcommands, use defineSubcommand instead of manually branching on interaction.options.getSubcommand():

src/commands/config.ts
import { SlashCommandBuilder } from "discord.js";
import { defineCommand, defineSubcommand } from "@bight-ts/core";
const view = defineSubcommand({
name: "view",
description: "View the current configuration.",
async execute({ interaction, context }) {
const settings = await context.services.guildSettings.get(
interaction.guildId!,
);
await interaction.reply(`Prefix: ${settings.prefix}`);
},
});
const reset = defineSubcommand({
name: "reset",
description: "Reset configuration to defaults.",
build: (builder) =>
builder.addBooleanOption((o) =>
o
.setName("confirm")
.setDescription("Confirm the reset.")
.setRequired(true),
),
async execute({ interaction, context }) {
// Handle reset logic
await interaction.reply("Configuration reset.");
},
});
export default defineCommand({
data: new SlashCommandBuilder()
.setName("config")
.setDescription("Manage bot configuration."),
subcommands: [view, reset],
});

Each subcommand defines its own execute handler and can add options through the build callback.

Commands support these additional properties alongside data and execute:

PropertyTypeDescription
preconditionsstring[]Named preconditions to evaluate before execution. See Preconditions.
cooldownnumberCooldown duration in milliseconds between invocations per user.
devOnlybooleanWhen true, the command is blocked in production environments.
deploymentCommandDeploymentTarget specific guilds or global deployment.
onDeniedBightDeniedHandlerCustom handler when a precondition rejects the user.
autocompleteFunctionHandler for autocomplete interactions on this command’s options.

Changes to command metadata (name, description, options) require a deploy to Discord. Runtime logic changes inside execute() do not.

Terminal window
pnpm deploy:commands:guild # push to test guild (instant)
pnpm deploy:commands # push globally (up to 1 hour cache delay)

See Command Deploy Modes for the full deployment strategy.