Commands
Register slash commands, typed options and optional text aliases.
Examples use the bot client from Your first bot.
Define your commands
Command names use lowercase letters, digits, underscores and hyphens, up to 32 characters. A bot can register up to 50 commands, each with up to 25 options. Replacing definitions keeps IDs for unchanged application, server and name combinations.
await bot.registerCommands([{
name: 'greet',
description: 'Say hello to someone',
contexts: ['server'],
options: [{ name: 'person', description: 'Who to greet', type: 'user', required: true }],
}]);
bot.command('greet', interaction => {
const personId = interaction.data.values.person;
return interaction.reply(`Hello <@${personId}>!`);
});Option types
All IDs stay strings. Roles require a server context and must belong to that server. User and mentionable values in DMs can refer only to conversation participants. Do not convert IDs to JavaScript numbers.
| Type | Value |
|---|---|
| string | Text |
| integer | A whole number |
| number | A number, including decimals |
| boolean | True or false |
| user | A user ID string |
| channel | A channel ID string |
| role | A role ID string in this server |
| mentionable | A user or role ID string |
Choices and bounds
String, integer and number options can offer up to 25 static choices. Each choice has a name and a value matching its option type. Numeric options support minValue and maxValue; strings support minLength and maxLength. The API checks both the definition and the submitted value.
Autocomplete and nested subcommands are not available yet. Use static choices and separate command names.
await bot.registerCommands([{
name: 'volume', description: 'Choose a volume', contexts: ['server'],
options: [{
name: 'level', description: 'How loud?', type: 'number', required: true,
minValue: 0, maxValue: 2,
choices: [{ name: 'Quiet', value: 0.5 }, { name: 'Normal', value: 1 }],
}],
}]);Contexts and permissions
Use contexts to choose server, dm or both. A serverId limits a definition to an installed development server. The permissions list describes what the invoking member must have; it does not grant the bot new capabilities.
Command handlers share ordered event processing. Acknowledge or defer promptly, then move long jobs into a background promise or task.
Text commands
A command can have up to five aliases. Registered text commands and mentions can be delivered without Message Content. Match the application’s configured prefix in your message handler; aliases alone do not make the SDK run a handler. Broader message listeners need Message Content permission.