Building bots
Commands
Register slash commands with typed options, and prefix commands for the command list.
Commands are what people see when they type / in a channel your bot is in. There are two kinds:
- Slash commands run on your bot: Bafflux checks the options, then sends your bot an interaction to answer.
- Prefix commands (like
!help) are only listed in the picker so people can find them. They arrive as normal messages; your bot reads them fromMESSAGE_CREATE.
Registering
Send the full list with PUT. It replaces every command in that scope, so bots usually do this each time they start.
curl -X PUT https://bafflux.com/api/applications/$APP_ID/commands \
-H "Authorization: Bot $BOT_TOKEN" \
-H "Content-Type: application/json" \
-d '[
{ "name": "ping", "description": "Checks the bot is awake" },
{ "name": "say", "description": "Repeats what you type",
"options": [
{ "name": "text", "description": "What to say", "type": "string", "required": true },
{ "name": "times", "description": "How many times", "type": "integer" }
] },
{ "kind": "prefix", "prefix": "!", "name": "help", "description": "Lists commands" }
]'The answer is the saved list, each command with its id.
| Endpoint | What |
|---|---|
GET /api/applications/{appId}/commands | Commands available everywhere your bot is |
PUT /api/applications/{appId}/commands | Replace them |
GET /api/applications/{appId}/servers/{serverId}/commands | Commands only for one server (the bot must be in it) |
PUT /api/applications/{appId}/servers/{serverId}/commands | Replace them |
DELETE /api/applications/{appId}/commands/{commandId} | Remove one command |
These work with the bot's token or while logged in to the portal as the app's owner. Changes show up in the picker within a minute.
The command object
| Field | Type | Notes |
|---|---|---|
name | string | Slash: 1-32 lowercase letters, numbers, - or _. Prefix: 1-32 characters, no spaces |
description | string | Slash: 1-100 characters, required. Prefix: up to 100 |
kind | "slash" or "prefix" | Defaults to "slash" |
prefix | string | Prefix commands only: 1-5 characters, no spaces, like ! or . |
options | array | Slash commands only, up to 25 |
Names must be unique within a list (per kind). You can have up to 100 commands everywhere, plus up to 100 in each server.
Options
| Field | Type | Notes |
|---|---|---|
name | string | 1-32 lowercase letters, numbers, - or _ |
description | string | 1-100 characters |
type | string | One of the types below. Defaults to string |
required | boolean | Defaults to false. Required options must come before optional ones |
| Type | What people type | What your bot gets |
|---|---|---|
string | Any text, 1-2000 characters | The text |
integer | 42 | A number |
number | 4.5 | A number |
boolean | true, false, yes, no, on, off | true or false |
user | @someone | Their user ID, as a string |
role | @Role | The role ID, as a string |
channel | A channel ID | The channel ID, as a string |
Bafflux checks types and required options before your bot hears about the command, so you can trust what arrives.
How people fill in options
After picking a command, people type each option as name: value, in any order:
/say text: hello there times: 3A command with a single option also takes everything after the name as that option: /say hello there. The picker shows the option names next to each command, and fills in the first one for commands that have several.