CIRCE / DOCUMENTATION
Commands
Slash commands with defineCommand.
On this page
A file in src/commands/ whose default export is a defineCommand is a slash command. The name defaults to the kebab-case file name unless the builder sets one; duplicates are reported at scan time.
defineCommand({
builder: CommandBuilder,
execute(ctx: CommandContext): void | Promise<void>,
guards?: Guard[],
autocomplete?: AutocompleteHandler,
metadata?: object,
});
| Field | Purpose |
|---|---|
builder |
A discord.js SlashCommandBuilder. |
execute |
The handler. Receives a command context. |
guards |
Preconditions run before execute. See Guards. |
autocomplete |
See Autocomplete. |
metadata |
Your data. Circe never reads it. |
Example
// src/commands/ban.ts
import { defineCommand, guildOnly, hasPermission } from "@sxnnyside/circe";
import { MessageFlags, PermissionFlagsBits, SlashCommandBuilder } from "discord.js";
export default defineCommand({
builder: new SlashCommandBuilder()
.setName("ban")
.setDescription("Bans a member")
.addUserOption((o) => o.setName("target").setDescription("Who").setRequired(true)),
guards: [guildOnly(), hasPermission(PermissionFlagsBits.BanMembers)],
async execute({ interaction, logger }) {
const target = interaction.options.getUser("target", true);
await interaction.guild?.members.ban(target);
logger.info(`Banned ${target.tag}`);
await interaction.reply({ content: "Done.", flags: MessageFlags.Ephemeral });
},
});
Notes
- Subfolders of
commands/are cosmetic. - Generate one with
circe add command. - For
/parent child, use command groups.
