Connect
- Get the URL from
GET /api/v1/gateway/bot(todaywss://falafy.com.br/gateway). - Send
{"op":"IDENTIFY","token":"Bot YOUR_TOKEN","intents":513}within 10 seconds. - Receive
READYwith your user, servers, channels and roles, and theresumeId. - Send
{"op":"PING"}every 30 seconds (the server closes connections silent for more than 75 s). Each event arrives as{"op":"EVENT","event":{"t":"MESSAGE_CREATE","d":{...}},"seq":42}.
Resume after a drop
Keep the READY resumeId and the last seq. When reconnecting, send {"op":"RESUME","token":"Bot YOUR_TOKEN","sessionId":"RESUME_ID","seq":42}: missed events arrive in order, then RESUMED. If you get INVALID_SESSION, IDENTIFY again. The session keeps its intents.
Intents
Add up the values of the intents the bot needs. Without intents, every non-privileged one applies. Those marked ★ are privileged: turn each one on in the portal before asking for it.
| Intent | Value | Events |
|---|---|---|
SERVERS | 1 | SERVER_CREATE/DELETE, CHANNEL_*, ROLE_*, CHANNELS_SYNC, THREAD_* |
SERVER_MEMBERS ★ | 2 | MEMBER_JOIN, MEMBER_LEAVE, MEMBER_UPDATE |
SERVER_MODERATION | 4 | MEMBER_WARNING |
SERVER_EXPRESSIONS | 8 | EXPRESSIONS_UPDATE |
SERVER_VOICE_STATES | 128 | VOICE_STATE_UPDATE |
SERVER_PRESENCES ★ | 256 | PRESENCE_UPDATE, ACTIVITY_UPDATE |
SERVER_MESSAGES | 512 | MESSAGE_CREATE/UPDATE/DELETE, PIN_* |
SERVER_MESSAGE_REACTIONS | 1024 | REACTION_ADD, REACTION_REMOVE |
SERVER_MESSAGE_TYPING | 2048 | TYPING |
DIRECT_MESSAGES | 4096 | MESSAGE_* (DM), DM_CREATE |
DIRECT_MESSAGE_REACTIONS | 8192 | REACTION_* (DM) |
DIRECT_MESSAGE_TYPING | 16384 | TYPING (DM) |
MESSAGE_CONTENT ★ | 32768 | content / embeds / attachments / components |
INTERACTION_CREATE always arrives, with no intent. So do the bot’s own server joins and leaves.
Close codes
4000bad frame ·4002no IDENTIFY in time ·4003no heartbeat: reconnect and RESUME.4001invalid or rotated token: don’t reconnect with the same token.4004too many connections for the same bot.4013invalid intents ·4014privileged intent not enabled in the portal.
Scale
Today a bot uses one connection (up to 10 at once per bot). Sharding isn’t needed; if it ever is, it will come as a new IDENTIFY option without breaking connected bots.