Events
Your server's event stream: types, format, long-polling with a cursor and Server-Sent Events, with ready-to-use reading loops.
On this page
Event types Format Long-polling Reading loop in PythonReading loop in Node.js Server-Sent Events Which mechanism to choose?Robert records your server's useful events and offers them in two ways: you fetch them (event stream, on this page) or Robert calls you (outgoing webhooks). Both share the same events, in the same format.
You need a key with the events.read scope, on a Premium or higher server.
Event types
| Type | When |
|---|---|
member.join |
A member joins the server |
member.leave |
A member leaves the server |
member.level_up |
A member gains a level |
message.create |
A message is posted in a channel linked to a bridge |
case.create |
A sanction is entered in the record (by a moderator, auto-moderation or the API) |
giveaway.end |
A giveaway ends |
ticket.open · ticket.close |
A ticket is opened or closed |
bridge.command |
A console command is sent to a bridge from Discord |
A webhook's "Test" button also sends a special ping event, which cannot be subscribed to.
Only servers that need it publish
Robert only keeps a server's events if it has at least one bridge, one webhook or one events.read key. Events are kept for 24 hours or 10,000 per server, whichever is reached first.
Format
{
"id": "e_4f9a0c2b7d1e3a5c8b60",
"type": "member.level_up",
"created_at": 1791370000,
"cursor": "djE6MTI0NA",
"data": { "user_id": "123456789012345678", "name": "Lina", "level": 13, "xp": 9100 }
}
data is a JSON object whose content depends on the type. Examples:
// member.join
{ "user": { "id": "123456789012345678", "name": "Steve", "bot": false } }
// case.create
{ "number": 43, "user_id": "123456789012345678", "user_name": "Lina", "action": "timeout", "reason": "Spam",
"duration": 600, "moderator": { "id": "111111111111111111", "name": "Hugo" } }
// message.create (channel linked to a bridge)
{ "bridge_id": "b_9f2c41d07a1b", "channel_id": "800000000000000002", "message_id": "900000000000000123",
"author": { "id": "400000000000000001", "name": "Jimmy" }, "content": "Hello miners" }
// bridge.command
{ "bridge_id": "b_9f2c41d07a1b", "command_id": "cmd_7a2e91", "command": "whitelist add Steve",
"by": { "id": "111111111111111111", "name": "Hugo" } }
Fields may be added
Ignore fields you do not know: Robert may add some to data without changing version. Existing fields never change meaning.
Long-polling
GET /events: a request that waits for something new (up to wait seconds, 25 at most) before answering.
| Parameter | Description |
|---|---|
cursor |
The previous response's next_cursor. latest: only receive what will happen from now on. Without cursor: the latest events |
types |
Comma-separated types (member.join,case.create). An unknown type gives 400 invalid_types |
wait |
0 to 25 seconds of maximum wait (0 by default) |
limit |
1 to 100 events per response |
The response is immediate if there are events; otherwise it arrives after wait seconds with an empty items. In every case, resume with next_cursor: you lose nothing and receive nothing twice.
# Start "now", then wait for member joins
curl -s -H "Authorization: Bearer $ROBERT_KEY" "$API/events?cursor=latest"
# → { "items": [], "next_cursor": "djE6MTI0NA" }
curl -s -H "Authorization: Bearer $ROBERT_KEY" "$API/events?cursor=djE6MTI0NA&types=member.join&wait=25"
Reading loop in Python
import json, os, time, urllib.request, urllib.error
API = "https://robert-bot.com/api/v1/public-api/guilds/987654321098765432"
KEY = os.environ["ROBERT_KEY"]
def fetch(cursor):
req = urllib.request.Request(
f"{API}/events?cursor={cursor}&types=member.join,case.create&wait=25",
headers={"Authorization": f"Bearer {KEY}"},
)
with urllib.request.urlopen(req, timeout=40) as resp: # a bit more than wait
return json.load(resp)
cursor = "latest"
while True:
try:
page = fetch(cursor)
except urllib.error.HTTPError as err:
if err.code == 429: # quota or rate: wait
time.sleep(int(err.headers.get("Retry-After", "10")))
continue
raise
except OSError: # network: retry
time.sleep(5)
continue
for event in page["items"]:
print(event["type"], event["data"])
cursor = page["next_cursor"] # save it to resume after a stop
Reading loop in Node.js
const API = "https://robert-bot.com/api/v1/public-api/guilds/987654321098765432";
const headers = { Authorization: `Bearer ${process.env.ROBERT_KEY}` };
let cursor = "latest";
for (;;) {
try {
const res = await fetch(`${API}/events?cursor=${cursor}&wait=25`, { headers });
if (res.status === 429) { await sleep(Number(res.headers.get("Retry-After") ?? 10) * 1000); continue; }
if (!res.ok) throw new Error(`${res.status} ${(await res.json()).error}`);
const page = await res.json();
for (const event of page.items) console.log(event.type, event.data);
cursor = page.next_cursor;
} catch (err) {
console.error(err);
await sleep(5000);
}
}
function sleep(ms) { return new Promise((r) => setTimeout(r, ms)); }
Each loop turn uses one request per response of your daily quota: with wait=25, that is about 3,400 requests per day at most when nothing happens. On a Premium server (5,000 requests per day), a webhook is often more economical.
Server-Sent Events
GET /events/stream returns the same events in text/event-stream format:
retry: 1000
id: djE6MTI0NQ
event: member.join
data: {"id":"e_4f9a0c2b7d1e3a5c8b60","type":"member.join","created_at":1791370000,"data":{"user":{"id":"123456789012345678","name":"Steve","bot":false}}}
idis the event's cursor; send it back in theLast-Event-IDheader (or?cursor=) to resume.eventis the type. Parameters:typesandwait(0 to 25, 25 by default).- The connection closes as soon as there are events, or after
waitseconds, withretry: 1000: the client reconnects right away. A standard SSE client does this on its own.
curl -N -H "Authorization: Bearer $ROBERT_KEY" -H "Accept: text/event-stream" \
"$API/events/stream?types=member.join"
Not from a browser
EventSource cannot send the Authorization header, and your key must never end up in your visitors' browser anyway. Read the stream from your server (the SDK offers streamEvents and sseEvents) and relay it to your pages.
Which mechanism to choose?
| Long-polling | SSE | Webhook | |
|---|---|---|---|
| Who initiates | You | You | Robert |
| Needs a public URL | No | No | Yes (HTTPS) |
| Resume after a stop | Cursor | Last-Event-ID |
Robert's automatic retries (10 s, 1 min, 10 min) |
| Ideal for | Scripts, services behind a firewall | Clients that handle SSE | Always-on sites and services |
Spotted a mistake? Got a question? Let us know on the support server.