baff.gg Docs Developer Portal

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: baff.gg 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 from MESSAGE_CREATE.

Registering

Send the full list with PUT. It replaces every command in that scope, so bots usually do this each time they start.

bash
curl -X PUT https://baff.gg/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.

EndpointWhat
GET /api/applications/{appId}/commandsCommands available everywhere your bot is
PUT /api/applications/{appId}/commandsReplace them
GET /api/applications/{appId}/servers/{serverId}/commandsCommands only for one server (the bot must be in it)
PUT /api/applications/{appId}/servers/{serverId}/commandsReplace 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

FieldTypeNotes
namestringSlash: 1-32 lowercase letters, numbers, - or _. Prefix: 1-32 characters, no spaces
descriptionstringSlash: 1-100 characters, required. Prefix: up to 100
kind"slash" or "prefix"Defaults to "slash"
prefixstringPrefix commands only: 1-5 characters, no spaces, like ! or .
optionsarraySlash commands only, up to 25 (plain options, or subcommands)

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

FieldTypeNotes
namestring1-32 lowercase letters, numbers, - or _
descriptionstring1-100 characters
typestringOne of the types below, or subcommand / subcommand_group. Defaults to string
requiredbooleanDefaults to false. Required options must come before optional ones
TypeWhat people typeWhat your bot gets
stringAny text, 1-2000 charactersThe text
integer42A number
number4.5A number
booleantrue, false, yes, no, on, offtrue or false
user@someoneTheir user ID, as a string
role@RoleThe role ID, as a string
channelA channel IDThe channel ID, as a string

baff.gg checks types and required options before your bot hears about the command, so you can trust what arrives.

Subcommands

Group related actions under one command, like /partner add, /partner remove and /partner list. Options get two more types:

TypeHoldsNotes
subcommandIts own options (plain options only)Can be at the top of a command or inside a group
subcommand_groupoptions that are all subcommands (at least one)Only at the top of a command

A command's options are either all subcommands and groups, or all plain options, never a mix. Groups can't hold groups and subcommands can't hold subcommands, so the deepest name is /command group subcommand. Subcommands and groups have a name and description like any option, can't be required, and each holds up to 25 options. Required options come first within each subcommand.

json
{ "name": "partner", "description": "Manage partnered servers",
  "options": [
    { "name": "add", "description": "Partner a server", "type": "subcommand",
      "options": [
        { "name": "server", "description": "Server id, invite or name", "type": "string", "required": true },
        { "name": "note", "description": "Why", "type": "string" }
      ] },
    { "name": "list", "description": "List partnered servers", "type": "subcommand" }
  ] }

The command picker lists each subcommand as its own entry (/partner add, /partner list) with the subcommand's description, and people type them out the same way: /partner add server: Baff Club. Your bot receives the subcommand it picked inside data.options (see Interactions).

How people fill in options

After picking a command, people type each option as name: value, in any order:

/say text: hello there times: 3

A 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.