Bot integration
The contract between the Discord bot process and Robert's API, covering the token, configuration, events, actions and the heartbeat.
On this page
Overview Authentication Reading the configuration GET /bot/guilds/{guild_id}/configGET /bot/changes?since={timestamp}GET /bot/premium/{guild_id} Reporting a server's state POST /bot/guilds/{guild_id}/state Sending events POST /bot/eventsIdempotent batches with batch_id Running dashboard actions GET /bot/actions?limit=50POST /bot/actions/{action_id}Action kinds Heartbeat POST /bot/heartbeat Configuration on the API side Good practiceRobert is made of two programs: the API (which serves the dashboard and stores the configuration) and the bot (the process connected to the Discord gateway). They talk through an internal API, described on this page.
Who is this page for?
For people who develop or host Robert. If you simply want to read your server's data from your website, use the key-based public API.
Overview
The bot never receives calls from the API: it is always the bot that asks. Its life cycle comes down to five things:
- Read the configuration of each server, then only reload what has changed.
- Report its presence on servers (joining, leaving, member count).
- Send its events: logs, sanctions, statistics, tickets, giveaways, form responses.
- Fetch and run the actions requested from the dashboard, then report back.
- Send a regular heartbeat, used by the status page.
Authentication
Every route starts with https://robert-bot.com/api/v1/bot/ and requires the header:
Authorization: Bot <BOT_API_TOKEN>
BOT_API_TOKEN is a shared secret, set in the environment of both the API and the bot. It is not the bot's Discord token.
| Situation | Response |
|---|---|
BOT_API_TOKEN is not set on the API side |
503 bot_api_disabled |
| Header missing or wrong token | 401 bad_bot_token |
These routes use neither a cookie nor a CSRF token. Their rate limit is generous: 6,000 requests per minute, with a burst of 2,000. Errors follow the common format.
Reading the configuration
GET /bot/guilds/{guild_id}/config
Returns a server's full configuration. Unlike the dashboard's version, secret settings (a custom bot's token, for example) are not masked: the bot needs them to work. These secrets are encrypted at rest in the API's database.
{
"guild_id": "987654321098765432",
"tier": "premium",
"limits": { "automod_rules": 60, "backups_stored": 25 },
"general": { "language": "fr", "timezone": "Europe/Paris", "embed_color": "#ff8a3d", "prefix": "!" },
"modules": {
"welcome": { "enabled": true, "settings": { "join_channel": "800000000000000002" }, "version": 3 }
},
"customized": ["welcome"],
"updated_at": 1790812800
}
tierisfree,premium,proornetwork;limitsholds every limit of that plan (-1= unlimited).modulesholds every module, with its default values when it has never been configured.
GET /bot/changes?since={timestamp}
Returns the servers whose configuration has changed since since (1,000 at most, oldest first):
{
"now": 1790812860,
"guilds": [ { "id": "987654321098765432", "updated_at": 1790812800 } ]
}
The bot polls this route every few seconds, reloads the configuration of the servers listed, then reuses now as the next since value.
A server reappears in this list whenever its settings change, and also when its plan changes: a slot being assigned or freed, a change of plan, and the end of a subscription that lapsed without renewal. The bot therefore has nothing else to watch in order to apply the right limits.
GET /bot/premium/{guild_id}
Returns only the plan and its limits: {"tier": "pro", "limits": {…}}.
Reporting a server's state
POST /bot/guilds/{guild_id}/state
Call it when the bot joins or leaves a server, and when the server's details change.
{ "present": true, "name": "The Gang", "icon": "a1b2c3", "owner_id": "123456789012345678", "member_count": 1284 }
present defaults to true; send false when the bot is removed from the server. The dashboard relies on this to show “Robert not added”.
Sending events
POST /bot/events
Body: {"batch_id": "…", "events": [ … ]}, 500 events at most per call. Each event carries a type and a guild_id. Events with an invalid guild_id are ignored.
type |
Purpose | Main fields |
|---|---|---|
log |
A line on the Logs page | log_type, category, user_id, user_name, channel_id, summary, data, created_at |
case |
A sanction added to the record | user_id, user_name, action, reason, duration, moderator_id, moderator_name |
member_stats |
A member's state for the leaderboards (replaces the previous one) | user_id, name, avatar, xp, level, messages, voice_minutes, balance, bank, invites, reputation |
stats |
The day's counters (added to the previous ones) | day, members, joins, leaves, messages, voice_minutes, commands |
hourly |
The peak-hours map (added) | dow (0 to 6), hour (0 to 23), messages |
ticket |
A ticket being created or updated | id, number, user_id, user_name, category, subject, status, claimed_by, created_at, closed_at, rating, transcript |
giveaway |
A giveaway's progress | id, status, entries, winner_ids |
form_response |
A response to a form | id, form, user_id, user_name, answers |
Example:
{
"batch_id": "bot0-1790812800-42",
"events": [
{ "type": "log", "guild_id": "987654321098765432", "log_type": "message_delete", "category": "messages", "user_id": "123456789012345678", "summary": "Message deleted" },
{ "type": "stats", "guild_id": "987654321098765432", "messages": 42, "joins": 3 },
{ "type": "case", "guild_id": "987654321098765432", "user_id": "123456789012345678", "action": "warn", "reason": "Flooding", "moderator_name": "Robert" }
]
}
The response counts what was received and returns the number assigned to each sanction:
{
"ok": true,
"received": { "log": 1, "stats": 1, "case": 1 },
"cases": [ { "index": 2, "guild_id": "987654321098765432", "number": 129 } ]
}
In cases, index is the position of the case event in the batch sent and number its number in the server's record: the bot can then show “case #129” in its reply.
A few details:
- For
statsandhourly, send differences since the last send, not totals. Onlymembersis an absolute value. - For
case,actioniswarn,timeout,kick,ban,unban,untimeout,noteorsoftban;durationis in seconds. - Group events and send them in batches rather than making one call per event.
Idempotent batches with batch_id
stats and hourly are counters that add up: a batch sent twice would skew the statistics. To avoid that, add a batch_id to the body: a unique string of at most 80 characters that you generate for each batch.
If the bot resends the same batch after a network failure, the API does not replay it: it answers with the original response, plus "duplicate": true. Batch identifiers are kept for 48 hours. Without a batch_id, every call is treated as a new batch.
Running dashboard actions
When someone posts an embed, starts a giveaway or lifts a sanction from the dashboard, the API creates an action that the bot comes to collect.
GET /bot/actions?limit=50
Returns the actions to handle (50 by default, 200 at most), oldest first, and marks them as delivered.
{
"actions": [
{
"id": "0c6f3b1e9a7d4c52b8e1f0a39d2c7b64",
"guild_id": "987654321098765432",
"kind": "send_message",
"payload": { "channel_id": "800000000000000002", "message": { "content": "Hello", "embed": null } },
"created_at": 1790812800,
"created_by": "123456789012345678",
"attempt": 1
}
]
}
An action that was delivered but not acknowledged within 60 seconds is handed out again on the next call, with an attempt field that goes up (1, 2, 3…). After 5 deliveries without acknowledgement, the API marks it failed with the result {"error": "Aucun acquittement du bot"}, and the dashboard shows it as failed.
Handle actions idempotently
Since an action can be delivered several times, the same id must always produce the same effect, once only: remember the identifiers you have already handled, and acknowledge again without replaying the action if it comes back.
POST /bot/actions/{action_id}
Acknowledges the action by reporting the outcome: {"status": "done", "result": {"message_id": "…"}} or {"status": "failed", "result": {"error": "…"}}. The dashboard then shows “done” or “failed”.
Action kinds
kind |
Origin | What the bot must do |
|---|---|---|
send_message, edit_message |
Messages & embeds page | Post or edit a message (channel_id, message) |
publish_panel, ticket_panel, form_panel, rules_panel, verification_panel, role_panel |
Panel-based modules | Post or update the panel concerned |
sync_commands |
Dashboard | Resynchronise the server's slash commands |
giveaway_start |
A giveaway being created | Post the giveaway; the payload holds the full giveaway object |
giveaway_end, giveaway_reroll, giveaway_cancel |
Giveaways page | End, reroll or cancel (giveaway_id) |
notify_warn |
A warning added from the web | Notify the member (user_id, case, reason) |
unban, untimeout |
A sanction lifted from the web | Unban or remove the timeout (user_id, case) |
form_decision |
A response accepted or rejected | Apply the decision (response_id, decision, note) |
appeal_submitted, appeal_decision |
Sanction appeals | Notify the team, then apply the decision |
Heartbeat
POST /bot/heartbeat
{ "component": "bot:0", "info": { "guilds": 128, "latency_ms": 42 } }
component identifies the process (bot by default; use bot:0, bot:1… for several shards). The response returns the server time: {"ok": true, "now": 1790812860}.
The Status page considers the bot down if no component whose name starts with bot has been heard from for 180 seconds. A heartbeat every 30 to 60 seconds is therefore a good rhythm.
Configuration on the API side
| Environment variable | Purpose |
|---|---|
BOT_API_TOKEN |
The secret shared between the API and the bot. Without it, the bot API is disabled |
DISCORD_BOT_TOKEN |
The bot's Discord token, used by the API for web server management and backups |
DISCORD_CLIENT_ID, DISCORD_CLIENT_SECRET |
The Discord application, for signing in to the dashboard |
ROBERT_PUBLIC_URL |
The site's public address, used for redirects |
Good practice
- Tolerate outages: if the API does not answer, keep the last known configuration in memory and resend the events later, with the same
batch_id. - Honour the plan limits returned in
limits: the bot is the one that enforces them in the last resort. - Always acknowledge an action, even when it fails: otherwise it will be handed to you up to five times before being marked as failed.
- Never log
BOT_API_TOKENor the raw configuration, which contains secrets.
Spotted a mistake? Got a question? Let us know on the support server.