Bots

A bot is an account your own program runs: it welcomes people, answers commands, moderates, posts updates. It has a BOT tag next to its name, and your program talks to The Hub for it through the API.

Making a bot

  1. Create it in the dashboard → Bots (or in The Hub: Settings → Bots). Copy the token it shows you: it's only shown once. New token makes another and switches the old one off.
  2. Choose its permissions: what its invite link asks for, like Send messages or Kick members. People adding it can untick any of them.
  3. Invite it. The dashboard makes an invite link: https://the-hub.coffee/app/?add_bot=<bot ID>&perms=<number>. Anyone with Manage space can open it and add your bot, if it's public. A private bot can only be added by you.
  4. Run its program, on any computer or server you like.

When a bot joins with permissions, it gets a role of its own carrying them, never more than the person adding it has, and never Administrator. Space admins can change that role like any other. A bot can belong to one of your apps, so people see who made it. Each account can have up to 10 bots.

Talking to the API

Every request goes to https://the-hub.coffee/app/api.php?action=<name> with the token in a header:

Authorization: Bot vlb_…

(X-Bot-Token: vlb_… works too.) No cookies or CSRF token are needed. Send POST bodies as JSON with Content-Type: application/json. Every answer is JSON with "ok": true, or "ok": false and an "error".

Hearing new messages

GET api.php?action=bot_events&after=<message id> returns up to 100 new messages, oldest first, from every channel and direct message the bot can see (never its own), and last_id to pass as after next time.

Call it once without after when your bot starts: it returns no messages and the current last_id, so the bot doesn't answer things said before it was running. Then ask every second or two.

Each message has id, channel_id, server_id (null in a direct message), channel_type (text, forum, voice for a room's chat, or dm), channel_name, thread_id, author (id, username, display_name, bot, …), content, attachments, reply, reactions, created_at and edited_at; the API reference has the rest. Moderation replies have system: true. Only new messages come this way: edits, deletions and reactions don't.

A tiny bot

// Node 18+, saved as bot.mjs: answers "!ping" with "pong"
const API = 'https://the-hub.coffee/app/api.php?action=';
const headers = { Authorization: 'Bot ' + process.env.HUB_BOT_TOKEN, 'Content-Type': 'application/json' };
const call = (action, body) => fetch(API + action, body ? { method: 'POST', headers, body: JSON.stringify(body) } : { headers }).then(r => r.json());

let { last_id } = await call('bot_events');
setInterval(async () => {
    const r = await call('bot_events&after=' + last_id);
    last_id = r.last_id;
    for (const m of r.messages) {
        if (m.content === '!ping') await call('message_send', { channel_id: m.channel_id, content: 'pong', reply_to: m.id });
    }
}, 1500);

Slash commands

A bot registers commands; people in a space it's in see them when they type /, with their options.

await call('bot_commands_set', { commands: [
    { name: 'roll', description: 'Roll dice', options: [
        { name: 'dice', description: 'Like 2d6', type: 'string', required: true },
        { name: 'quiet', type: 'boolean' } ] },
    { name: 'pick', description: 'Pick a map', options: [
        { name: 'map', type: 'string', required: true, choices: [{ name: 'Mirage', value: 'mirage' }, { name: 'Dust 2', value: 'dust2' }] } ] },
] });
  • Without server_id they're for every space the bot is in; with one, for that space only (it wins over a global command of the same name). Each call replaces the whole list for that scope. bot_commands_get reads them back.
  • Up to 50 commands. Names are 1 to 32 lowercase letters, digits, - or _; descriptions up to 100 characters.
  • Up to 10 options, required ones first. Types: string, integer, boolean, user, channel, role; up to 25 choices. People type them in order (/roll 2d6 yes) or by name (/roll dice:2d6).
  • A command only shows in channels the bot can see.

Interactions

When someone runs a command, The Hub checks the options (a user must be in the space, an integer a number, a choice one of the choices…) and hands the bot an interaction with its next bot_events, in interactions (up to 50 at a time, each handed over once):

{ "id": 31, "token": "9f2c…", "kind": "command", "name": "roll", "data": { "dice": "2d6", "quiet": false },
  "user": { "id": 12, "username": "jonas", … }, "channel_id": 5, "channel_name": "general", "server_id": 2,
  "message_id": null, "created_at": 1791336070538 }

A user, channel or role option arrives as its id. An interaction is tied to the person who ran it: a bot can't make one. Answer it with its token, within 15 minutes:

interaction_respond typeWhat happens
messageA message from the bot in the channel, marked with who ran which command
ephemeralA reply only that person sees
deferred"bot is thinking…" in the channel; fill it in with interaction_edit
updateFor a button or menu: changes the message that was clicked

All of them take content and embeds, and all but ephemeral take components. type is message when you leave it out. interaction_edit (with the same token) changes the answer later, still within 15 minutes. An interaction can only be answered once: a second interaction_respond gets a 409. If the bot doesn't answer within 15 seconds, the person is told it didn't.

for (const i of r.interactions) {
    if (i.name === 'roll') await call('interaction_respond', { token: i.token, content: '🎲 ' + roll(i.data.dice) });
    if (i.name === 'pick') await call('interaction_respond', { token: i.token, type: 'ephemeral', content: 'Noted!' });
}

Buttons and menus

A bot's message can carry up to 5 rows of components: up to 5 buttons per row, or one select menu. Send them with message_send, message_edit or an interaction answer, as components:

await call('message_send', { channel_id, content: 'Ready?', components: [
    { components: [
        { type: 'button', style: 'success', label: 'Join', emoji: '✅', custom_id: 'join' },
        { type: 'button', style: 'link', label: 'Rules', url: 'https://example.com/rules' } ] },
    { components: [
        { type: 'select', custom_id: 'map', placeholder: 'Pick a map', min_values: 1, max_values: 1,
          options: [{ label: 'Mirage', value: 'mirage' }, { label: 'Dust 2', value: 'dust2', description: 'The classic' }] } ] },
] });
  • Button styles: primary, secondary, success, danger, and link (with an https:// url, opened in the browser; nothing is sent to the bot). Every other button and menu needs a custom_id, unique on the message, up to 100 characters. A button needs a label (up to 80 characters) or an emoji. disabled: true greys one out.
  • A menu has up to 25 options (label, value, optional description and emoji) and how many may be picked (min_values, max_values, 1 unless you say).
  • message_edit with components replaces them; [] takes them off.

A click is an interaction with kind: "component", the custom_id as its name, data: { custom_id, values } (the menu's picks) and the message_id it was on. The Hub checks the button is really on that message and the picks are among the options. Answer it like a command, or with type: "update" to change the clicked message itself (any of content, embeds, components) instead of posting a new one. tools/example-bot.php has a /roll whose "Roll again" button does exactly that.

Embeds

A bot can send up to 10 embeds with a message, as Discord bots do: message_send with embeds (and content, which may be empty). message_edit with embeds replaces them; [] takes them off.

await call('message_send', { channel_id, content: '', embeds: [{
    title: 'Friday match', url: 'https://example.com/match', color: 0xffc94d,
    description: '**Mirage** at 21:00',
    author: { name: 'Match bot', icon_url: 'https://example.com/bot.png' },
    fields: [{ name: 'Team A', value: 'Maya, Jonas', inline: true }, { name: 'Team B', value: 'Léa, Sam', inline: true }],
    thumbnail: { url: 'https://example.com/map.png' }, image: { url: 'https://example.com/banner.png' },
    footer: { text: 'Game Night' }, timestamp: '2026-10-23T21:00:00Z',
}] });
FieldLimit
title, author.name, a field's name256 characters
description4,096 characters, with the usual Markdown formatting
fields25, each value up to 1,024 characters; inline: true puts them side by side
footer.text2,048 characters
All the text of a message's embeds6,000 characters
colora number (0xffc94d) or "#ffc94d"
timestampISO 8601, or milliseconds

Links and pictures (url, author.url, author.icon_url, image.url, thumbnail.url, footer.icon_url) must be https://; anything else is dropped. Pictures from other sites show only for people who allowed embedded content; the others see a link. People can't send embeds, only bots and webhooks.

Limits

A bot can send 5 messages every 5 seconds, and make 120 POST requests a minute of any kind; more get a 429 answer, so wait a moment and try again.

Keeping the token safe

Anyone with the token can act as the bot. Keep it out of code you share (read it from an environment variable), and make a new one if it leaks. Deleting a bot takes it out of every space and switches its token off; its messages stay, shown as "Deleted bot".