prefix()
Define a text-based prefix command that users trigger by typing a prefix followed by the command name.
Signature
function prefix(command: Command): Command
Parameters
The command name (without prefix)
Human-readable description of what the command does
run
(ctx: MessageContext & { args: string[] }) => Promise<void> | void
required
Handler function that executes when the command is invoked
Return Value
Returns the same Command object (identity function for type safety).
Example
const sayCmd = prefix({
name: 'say',
description: 'Echo a message',
run: async (ctx) => {
const text = ctx.args.join(' ')
await ctx.reply(text || 'You didn\'t say anything!')
}
})
createBot({
prefix: '!',
commands: [sayCmd]
})
// User types: !say Hello world
// Bot replies: Hello world
slash()
Define a slash command that appears in Discord’s command menu.
Signature
function slash(command: SlashCommand): SlashCommand
Parameters
Show SlashCommand properties
The command name (must be lowercase, no spaces)
Description shown in Discord’s command menu
Array of command parameters/options
Array of subcommands (mutually exclusive with options and run)
run
(ctx: InteractionContext) => Promise<void> | void
Handler function (not used if subcommands are defined)
Return Value
Returns the same SlashCommand object (identity function for type safety).
Simple Command Example
const rollCmd = slash({
name: 'roll',
description: 'Roll a dice',
options: [{
name: 'sides',
description: 'Number of sides',
type: 'integer',
required: false
}],
run: async (ctx) => {
const sides = ctx.options.sides as number ?? 6
const result = Math.floor(Math.random() * sides) + 1
await ctx.reply(`You rolled a ${result}!`)
}
})
Subcommand Example
const modCmd = slash({
name: 'mod',
description: 'Moderation commands',
subcommands: [
{
name: 'kick',
description: 'Kick a user',
options: [{
name: 'user',
description: 'User to kick',
type: 'string',
required: true
}],
run: async (ctx) => {
const user = ctx.options.user
await ctx.reply(`Kicked ${user}`)
}
},
{
name: 'ban',
description: 'Ban a user',
options: [{
name: 'user',
description: 'User to ban',
type: 'string',
required: true
}],
run: async (ctx) => {
const user = ctx.options.user
await ctx.reply(`Banned ${user}`)
}
}
]
})
SlashCommandOption
Properties
Option name (lowercase, no spaces)
Description shown in Discord’s UI
type
'string' | 'integer' | 'number' | 'boolean' | 'subcommand' | 'subcommand_group'
The type of value this option accepts (defaults to ‘string’)
Whether this option must be provided (defaults to false)
Nested options (for subcommands and subcommand groups)
Notes
- Command names must be lowercase with no spaces
- Slash commands are automatically registered when passed to
createBot()
- You cannot mix
subcommands with options or run in the same command
- Options are automatically flattened and available via
ctx.options