Bot API reference
Gateway events
The bot gateway frame by frame. Opcodes, the payloads of Hello, Identify, Ready and Resume, and every event Klang dispatches, with a real example and the intent each needs.
Frames
Every frame, in both directions, is a JSON object with four fields:
| Field | Type | Notes |
|---|---|---|
op |
integer | The opcode. |
d |
any | The payload. null when the opcode carries nothing. |
s |
integer or null | The sequence number, only on events (op 0). It grows by one each time. |
t |
string or null | The event’s name, only on events. |
How to connect, compress and stay connected is in Gateway. This page is the list of what travels.
Opcodes
| Op | Name | Who sends it | In Klang |
|---|---|---|---|
0 |
Dispatch | Klang | Every event below. |
1 |
Heartbeat | Both | The bot, every heartbeat_interval; Klang, when one is late. |
2 |
Identify | Bot | Starts a session. |
3 |
Presence Update | Bot | The bot’s status. |
4 |
Voice State Update | Bot | Accepted, and does nothing yet. |
6 |
Resume | Bot | Picks a session up again. |
7 |
Reconnect | Klang | Before Klang restarts: reconnect and resume. |
8 |
Request Guild Members | Bot | Accepted, and doesn’t answer yet. |
9 |
Invalid Session | Klang | The session can’t be resumed. |
10 |
Hello | Klang | The first frame. |
11 |
Heartbeat ACK | Klang | The answer to each heartbeat. |
Any other opcode from the bot closes the connection with 4001.
Hello
Klang sends it as soon as the connection opens:
{ "op": 10, "d": { "heartbeat_interval": 41250 }, "s": null, "t": null }Heartbeat
The bot sends the last s it got, or null before any event. Klang answers with op 11:
{ "op": 1, "d": 2 }{ "op": 11, "d": null, "s": null, "t": null }When a heartbeat is 10 seconds late, Klang sends { "op": 1, "d": null } itself. Answer it with
a heartbeat at once.
Identify
| Field | Type | Notes |
|---|---|---|
token |
string | Required. The bot token, without Bot . |
intents |
integer | Required. See Intents. |
properties |
object | Required. os, browser and device, up to 100 characters each. Klang doesn’t use them. |
large_threshold |
integer, 50–250 | 50 by default. Above it, GUILD_CREATE only carries the bot’s own member. |
shard |
[0, 1] |
Optional. Anything else closes with 4010. |
presence |
object | Optional. The first status, as in Presence Update. |
compress |
boolean | Accepted and ignored. |
{
"op": 2,
"d": {
"token": "MTU3MTM1MDMzMjk2NTE0NjYyNA.aRe7xg.klang_…",
"intents": 46603,
"properties": { "os": "linux", "browser": "my_library", "device": "my_library" }
}
}46603 asks for GUILDS, GUILD_MEMBERS, GUILD_EXPRESSIONS, GUILD_MESSAGES,
GUILD_MESSAGE_REACTIONS, DIRECT_MESSAGES, DIRECT_MESSAGE_REACTIONS and MESSAGE_CONTENT.
Ready
The answer to Identify: event READY, always s 1. It needs no intent.
| Field | Type | Notes |
|---|---|---|
v |
integer | Always 10. |
user |
user | The bot’s own user. |
guilds |
array | Every server it’s in, as { "id", "unavailable": true }. Each one’s GUILD_CREATE follows. |
private_channels |
array | Always []: direct messages arrive as events. |
session_id |
string | For Resume. |
resume_gateway_url |
string | Where to reconnect to resume. |
application |
object | id and flags of the bot’s app. |
shard |
array | Only if Identify sent shard: [0, 1]. |
{
"op": 0,
"s": 1,
"t": "READY",
"d": {
"v": 10,
"user": {
"id": "1571350332965146624",
"username": "lighthouse",
"discriminator": "0",
"global_name": "Lighthouse",
"avatar": null,
"banner": null,
"accent_color": null,
"public_flags": 0,
"bot": true,
"flags": 0,
"verified": true,
"mfa_enabled": false,
"email": null,
"locale": "en-US"
},
"guilds": [{ "id": "1571350333212610560", "unavailable": true }],
"private_channels": [],
"session_id": "62450af77c4b4072ba3218ca3adf5c42",
"resume_gateway_url": "wss://bot-gateway.klang.gg",
"application": { "id": "1571350332965146624", "flags": 557056 }
}
}Resume
To pick a session up after the connection drops, open a new connection to resume_gateway_url
and send, instead of Identify:
| Field | Type | Notes |
|---|---|---|
token |
string | The bot token. |
session_id |
string | From READY. |
seq |
integer | The last s the bot got. |
{
"op": 6,
"d": {
"token": "MTU3MTM1MDMzMjk2NTE0NjYyNA.aRe7xg.klang_…",
"session_id": "62450af77c4b4072ba3218ca3adf5c42",
"seq": 54
}
}Klang sends every event after seq, with their own s, and then RESUMED, whose d is an
empty object. In this session the bot missed one message while it was away: it got that
MESSAGE_CREATE with s 55, and then:
{ "op": 0, "s": 56, "t": "RESUMED", "d": {} }If the session can’t be resumed, Klang answers Invalid Session with false. Send
Identify to start a new one; the same connection works:
{ "op": 9, "d": false, "s": null, "t": null }Klang keeps a session for about 3 minutes after its connection closes, whatever code the bot
closed it with. Sessions closed by Klang with a code that says not to reconnect, such as 4004,
can’t be resumed.
Presence Update
| Field | Type | Notes |
|---|---|---|
status |
string | Required. online, idle, dnd or invisible. offline counts as invisible. |
activities |
array | Up to 10. Accepted and ignored for now. |
since |
integer or null | Accepted and ignored. |
afk |
boolean | Accepted and ignored. |
{ "op": 3, "d": { "since": null, "activities": [], "status": "online", "afk": false } }Events and intents
These are the events Klang dispatches today, and the intent each needs. An event whose intent the bot didn’t ask for never arrives. Events not in this list aren’t sent; the compatibility table says which ones are coming.
| Event | Intent in a server | Intent in a DM |
|---|---|---|
READY, RESUMED, USER_UPDATE |
None | None |
INTERACTION_CREATE |
None | None |
GUILD_CREATE, GUILD_UPDATE, GUILD_DELETE |
GUILDS (1 << 0) |
— |
GUILD_ROLE_CREATE, GUILD_ROLE_UPDATE, GUILD_ROLE_DELETE |
GUILDS |
— |
CHANNEL_CREATE, CHANNEL_UPDATE, CHANNEL_DELETE |
GUILDS |
— |
THREAD_CREATE, THREAD_UPDATE, THREAD_DELETE |
GUILDS |
— |
THREAD_MEMBERS_UPDATE, THREAD_LIST_SYNC |
GUILDS |
— |
GUILD_MEMBER_ADD, GUILD_MEMBER_UPDATE, GUILD_MEMBER_REMOVE |
GUILD_MEMBERS (1 << 1) |
— |
MESSAGE_CREATE, MESSAGE_UPDATE, MESSAGE_DELETE, MESSAGE_DELETE_BULK |
GUILD_MESSAGES (1 << 9) |
DIRECT_MESSAGES (1 << 12) |
MESSAGE_REACTION_ADD, MESSAGE_REACTION_REMOVE, MESSAGE_REACTION_REMOVE_EMOJI, MESSAGE_REACTION_REMOVE_ALL |
GUILD_MESSAGE_REACTIONS (1 << 10) |
DIRECT_MESSAGE_REACTIONS (1 << 13) |
GUILD_BAN_ADD, GUILD_BAN_REMOVE |
GUILD_MODERATION (1 << 2) |
— |
GUILD_AUDIT_LOG_ENTRY_CREATE |
GUILD_MODERATION |
— |
WEBHOOKS_UPDATE |
GUILD_WEBHOOKS (1 << 5) |
— |
GUILD_EMOJIS_UPDATE, GUILD_STICKERS_UPDATE |
GUILD_EXPRESSIONS (1 << 3) |
— |
CHANNEL_PINS_UPDATE |
GUILDS |
DIRECT_MESSAGES |
MESSAGE_POLL_VOTE_ADD, MESSAGE_POLL_VOTE_REMOVE |
GUILD_MESSAGE_POLLS (1 << 24) |
DIRECT_MESSAGE_POLLS (1 << 25) |
AUTO_MODERATION_RULE_CREATE, AUTO_MODERATION_RULE_UPDATE, AUTO_MODERATION_RULE_DELETE |
AUTO_MODERATION_CONFIGURATION (1 << 20) |
— |
AUTO_MODERATION_ACTION_EXECUTION |
AUTO_MODERATION_EXECUTION (1 << 21) |
— |
Bans only reach bots that can see them: with Ban members or View audit log in the server. Audit log entries only reach bots with View audit log, and AutoMod events only bots with Manage server in it.
Two exceptions: the bot’s own GUILD_MEMBER_UPDATE arrives without GUILD_MEMBERS, and a
THREAD_MEMBERS_UPDATE about someone else needs GUILD_MEMBERS too, while one about the bot
itself doesn’t.
The examples below are the events’ d, from a real session.
Server events
GUILD_CREATE
One for each server after READY, and one when someone adds the bot to a server. It’s the
server with these fields added:
| Field | Type | Notes |
|---|---|---|
joined_at |
date | When the bot joined. |
large |
boolean | More members than large_threshold. |
unavailable |
boolean | Always false. |
member_count |
integer | |
members |
array of members | All of them with GUILD_MEMBERS in a server that isn’t large; otherwise only the bot. |
channels |
array | The server channels the bot can see. |
threads |
array | The active threads in them, up to 500. |
presences, voice_states, stage_instances, guild_scheduled_events, soundboard_sounds |
array | Always []. |
Shortened to one item per list:
{
"id": "1571350333212610560",
"name": "Harbor",
"icon": null,
"splash": null,
"discovery_splash": null,
"banner": null,
"description": null,
"owner_id": "1571350324312297472",
"afk_channel_id": null,
"afk_timeout": 300,
"widget_enabled": false,
"widget_channel_id": null,
"verification_level": 0,
"default_message_notifications": 1,
"explicit_content_filter": 0,
"roles": [
{
"id": "1571350333212610560",
"name": "@everyone",
"color": 0,
"colors": { "primary_color": 0, "secondary_color": null, "tertiary_color": null },
"hoist": false,
"icon": null,
"unicode_emoji": null,
"position": 0,
"permissions": "563261442739777",
"managed": false,
"mentionable": false,
"flags": 0
}
],
"emojis": [
{
"id": "1571350334105997312",
"name": "anchor",
"animated": false,
"roles": [],
"require_colons": true,
"managed": false,
"available": true
}
],
"stickers": [
{
"id": "1571350334407987200",
"name": "Wave",
"description": null,
"tags": "🌊",
"type": 2,
"format_type": 1,
"available": true,
"guild_id": "1571350333212610560"
}
],
"features": ["PIN_PERMISSION_MIGRATION_COMPLETE"],
"mfa_level": 0,
"application_id": null,
"system_channel_id": "1571350333212610562",
"system_channel_flags": 0,
"rules_channel_id": null,
"max_presences": null,
"max_members": 500000,
"vanity_url_code": null,
"premium_tier": 0,
"premium_subscription_count": 0,
"preferred_locale": "en-US",
"public_updates_channel_id": null,
"max_video_channel_users": 25,
"max_stage_video_channel_users": 0,
"approximate_member_count": 3,
"nsfw_level": 0,
"premium_progress_bar_enabled": false,
"hub_type": null,
"safety_alerts_channel_id": null,
"incidents_data": null,
"joined_at": "2026-11-15T02:25:14.129Z",
"large": false,
"unavailable": false,
"member_count": 3,
"voice_states": [],
"members": [
{
"nick": null,
"avatar": null,
"banner": null,
"roles": ["1571350334990995456"],
"joined_at": "2026-11-15T02:25:14.129Z",
"premium_since": null,
"deaf": false,
"mute": false,
"flags": 4,
"pending": false,
"communication_disabled_until": null,
"user": {
"id": "1571350332965146624",
"username": "lighthouse",
"discriminator": "0",
"global_name": "Lighthouse",
"avatar": null,
"banner": null,
"accent_color": null,
"public_flags": 0,
"bot": true
}
}
],
"channels": [
{
"id": "1571350333212610562",
"guild_id": "1571350333212610560",
"name": "general",
"position": 0,
"permission_overwrites": [],
"nsfw": false,
"flags": 0,
"parent_id": null,
"last_message_id": "1571350339420180482",
"rate_limit_per_user": 0,
"type": 0,
"topic": null,
"default_auto_archive_duration": 10080
}
],
"threads": [
{
"id": "1571350339420180480",
"type": 11,
"guild_id": "1571350333212610560",
"parent_id": "1571350333212610562",
"name": "Saturday plans",
"last_message_id": "1571350339550203904",
"rate_limit_per_user": 0,
"message_count": 1,
"total_message_sent": 1,
"member_count": 0,
"flags": 0,
"thread_metadata": {
"archived": false,
"auto_archive_duration": 10080,
"archive_timestamp": "2026-11-15T02:25:15.195Z",
"locked": false,
"create_timestamp": "2026-11-15T02:25:15.195Z"
},
"owner_id": "1571350324312297472"
}
],
"presences": [],
"stage_instances": [],
"guild_scheduled_events": [],
"soundboard_sounds": []
}GUILD_UPDATE
The whole server again, as GET /guilds/{guild.id} returns
it, when its name, picture, settings, emojis or stickers change. A new member alone doesn’t send
one.
GUILD_DELETE
The bot left the server, was removed, or the server was deleted. unavailable is always
false: Klang doesn’t send outages this way.
{ "id": "1571350476519395328", "unavailable": false }GUILD_ROLE_CREATE
{
"guild_id": "1571350333212610560",
"role": {
"id": "1571350450720231424",
"name": "Lifeguard",
"color": 15423319,
"colors": { "primary_color": 15423319, "secondary_color": null, "tertiary_color": null },
"hoist": false,
"icon": null,
"unicode_emoji": null,
"position": 1,
"permissions": "0",
"managed": false,
"mentionable": false,
"flags": 0
}
}A new role moves the ones above it, so GUILD_ROLE_UPDATEs for those roles come first.
GUILD_ROLE_UPDATE
The same shape as GUILD_ROLE_CREATE, with the role as it is now.
GUILD_ROLE_DELETE
{ "guild_id": "1571350333212610560", "role_id": "1571350450720231424" }Channel events
Klang compares what the bot could see before and after each change, so these events also say
when the bot gains or loses access to a channel: a channel it can now see arrives as
CHANNEL_CREATE, and one it can no longer see as CHANNEL_DELETE. Each carries the
server channel as it is now, or as it was for
CHANNEL_DELETE. Direct messages don’t send them.
CHANNEL_CREATE
{
"id": "1571350452318261248",
"guild_id": "1571350333212610560",
"name": "weather",
"position": 4,
"permission_overwrites": [],
"nsfw": false,
"flags": 0,
"parent_id": null,
"last_message_id": null,
"rate_limit_per_user": 0,
"type": 0,
"topic": null,
"default_auto_archive_duration": 10080
}CHANNEL_UPDATE
The channel after the change, here a new topic:
{
"id": "1571350452318261248",
"guild_id": "1571350333212610560",
"name": "weather",
"position": 4,
"permission_overwrites": [],
"nsfw": false,
"flags": 0,
"parent_id": null,
"last_message_id": null,
"rate_limit_per_user": 0,
"type": 0,
"topic": "Wind and waves",
"default_auto_archive_duration": 10080
}A new message doesn’t send one, even though last_message_id changes.
CHANNEL_DELETE
The channel as the bot last saw it, with the same fields as CHANNEL_UPDATE.
Thread events
THREAD_CREATE
A new thread in a channel the bot can see. A thread with no
messages yet has a last_message_id that doesn’t point to a message.
{
"id": "1571350454193115136",
"type": 11,
"guild_id": "1571350333212610560",
"parent_id": "1571350333212610562",
"name": "Lost and found",
"last_message_id": "1571350454193115136",
"rate_limit_per_user": 0,
"message_count": 0,
"total_message_sent": 0,
"member_count": 0,
"flags": 0,
"thread_metadata": {
"archived": false,
"auto_archive_duration": 10080,
"archive_timestamp": "2026-11-15T02:25:42.559Z",
"locked": false,
"create_timestamp": "2026-11-15T02:25:42.559Z"
},
"owner_id": "1571350324312297472"
}THREAD_UPDATE
The thread after a change: here it was locked.
{
"id": "1571350454193115136",
"type": 11,
"guild_id": "1571350333212610560",
"parent_id": "1571350333212610562",
"name": "Lost and found",
"last_message_id": "1571350454495105024",
"rate_limit_per_user": 0,
"message_count": 1,
"total_message_sent": 1,
"member_count": 0,
"flags": 0,
"thread_metadata": {
"archived": false,
"auto_archive_duration": 10080,
"archive_timestamp": "2026-11-15T02:25:42.559Z",
"locked": true,
"create_timestamp": "2026-11-15T02:25:42.559Z"
},
"owner_id": "1571350324312297472"
}THREAD_DELETE
{
"id": "1571350454193115136",
"guild_id": "1571350333212610560",
"parent_id": "1571350333212610562",
"type": 11
}THREAD_MEMBERS_UPDATE
Someone started or stopped following a thread whose channel the bot can see: in Klang, following
is Discord’s joining. member_count is how many follow it now, up to 50. Who started comes in
added_members, as thread members with their
member when Klang has it at hand; who stopped, in removed_member_ids. Nora followed
“Lost and found”:
{
"id": "1575719350375153664",
"guild_id": "1575719326438260736",
"member_count": 2,
"added_members": [
{
"id": "1575719350375153664",
"user_id": "1575718774140698624",
"join_timestamp": "2026-11-27T03:46:08.922Z",
"flags": 0,
"member": {
"nick": null,
"avatar": null,
"banner": null,
"roles": [],
"joined_at": "2026-11-27T03:46:03.006Z",
"premium_since": null,
"deaf": false,
"mute": false,
"flags": 0,
"pending": false,
"communication_disabled_until": null,
"user": {
"id": "1575718774140698624",
"username": "nora",
"discriminator": "0",
"global_name": "Nora",
"avatar": null,
"banner": null,
"accent_color": null,
"public_flags": 0
}
}
}
]
}And stopped:
{
"id": "1575719350375153664",
"guild_id": "1575719326438260736",
"member_count": 1,
"removed_member_ids": ["1575718774140698624"]
}THREAD_LIST_SYNC
The bot came to see a text channel that has active threads, because a role or an overwrite let it
in. It comes after that channel’s CHANNEL_CREATE, with the channels it covers in
channel_ids, their active threads, and the bot’s own thread
members among them in members. Not when the bot connects: GUILD_CREATE already has the
active threads. A channel without threads sends nothing.
{
"guild_id": "1575719326438260736",
"channel_ids": ["1575719352073846784"],
"threads": [
{
"id": "1575719352270979072",
"type": 11,
"guild_id": "1575719326438260736",
"parent_id": "1575719352073846784",
"name": "Night shifts",
"last_message_id": "1575719352270979072",
"rate_limit_per_user": 0,
"message_count": 0,
"total_message_sent": 0,
"member_count": 0,
"owner_id": "1575718768511942656",
"flags": 0,
"thread_metadata": {
"archived": false,
"auto_archive_duration": 10080,
"archive_timestamp": "2026-11-27T03:46:09.031Z",
"locked": false,
"create_timestamp": "2026-11-27T03:46:09.031Z"
}
}
],
"members": []
}Member events
These need GUILD_MEMBERS. A member with its user, and the
server’s ID in guild_id.
GUILD_MEMBER_ADD
{
"nick": null,
"avatar": null,
"banner": null,
"roles": [],
"joined_at": "2026-11-15T02:25:36.612Z",
"premium_since": null,
"deaf": false,
"mute": false,
"flags": 0,
"pending": false,
"communication_disabled_until": null,
"user": {
"id": "1571350329852973056",
"username": "ines",
"discriminator": "0",
"global_name": "Ines",
"avatar": null,
"banner": null,
"accent_color": null,
"public_flags": 0
},
"guild_id": "1571350333212610560"
}GUILD_MEMBER_UPDATE
The whole member after a change: a nickname, roles, a timeout, or their name or picture.
{
"nick": "Ines (visiting)",
"avatar": null,
"banner": null,
"roles": [],
"joined_at": "2026-11-15T02:25:36.612Z",
"premium_since": null,
"deaf": false,
"mute": false,
"flags": 0,
"pending": false,
"communication_disabled_until": null,
"user": {
"id": "1571350329852973056",
"username": "ines",
"discriminator": "0",
"global_name": "Ines",
"avatar": null,
"banner": null,
"accent_color": null,
"public_flags": 0
},
"guild_id": "1571350333212610560"
}GUILD_MEMBER_REMOVE
Someone left, or was kicked or banned.
{
"guild_id": "1571350333212610560",
"user": {
"id": "1571350329852973056",
"username": "ines",
"discriminator": "0",
"global_name": "Ines",
"avatar": null,
"banner": null,
"accent_color": null,
"public_flags": 0
}
}Message events
MESSAGE_CREATE
A message with the gateway’s extra fields: channel_type,
and in servers guild_id, the author’s member and each mention’s member. Without
MESSAGE_CONTENT, the content fields come empty, as in the
REST API. The bot also gets
its own messages.
Leo mentions the bot in a server:
{
"id": "1571350405442719744",
"channel_id": "1571350333212610562",
"type": 0,
"author": {
"id": "1571350327143452672",
"username": "leo",
"discriminator": "0",
"global_name": "Leo",
"avatar": null,
"banner": null,
"accent_color": null,
"public_flags": 0
},
"content": "<@1571350332965146624> what's the tide?",
"timestamp": "2026-11-15T02:25:30.936Z",
"edited_timestamp": null,
"tts": false,
"mention_everyone": false,
"mentions": [
{
"id": "1571350332965146624",
"username": "lighthouse",
"discriminator": "0",
"global_name": "Lighthouse",
"avatar": null,
"banner": null,
"accent_color": null,
"public_flags": 0,
"bot": true,
"member": {
"nick": null,
"avatar": null,
"banner": null,
"roles": ["1571350334990995456"],
"joined_at": "2026-11-15T02:25:14.129Z",
"premium_since": null,
"deaf": false,
"mute": false,
"flags": 4,
"pending": false,
"communication_disabled_until": null
}
}
],
"mention_roles": [],
"attachments": [],
"embeds": [],
"pinned": false,
"flags": 0,
"components": [],
"channel_type": 0,
"guild_id": "1571350333212610560",
"member": {
"nick": null,
"avatar": null,
"banner": null,
"roles": ["1571350334701588480"],
"joined_at": "2026-11-15T02:25:13.778Z",
"premium_since": null,
"deaf": false,
"mute": false,
"flags": 0,
"pending": false,
"communication_disabled_until": null
}
}Leo writes to the bot in their direct message: no guild_id and no member, and channel_type
is 1.
{
"id": "1571350402712227840",
"channel_id": "1571350402322157569",
"type": 0,
"author": {
"id": "1571350327143452672",
"username": "leo",
"discriminator": "0",
"global_name": "Leo",
"avatar": null,
"banner": null,
"accent_color": null,
"public_flags": 0
},
"content": "Thanks!",
"timestamp": "2026-11-15T02:25:30.285Z",
"edited_timestamp": null,
"tts": false,
"mention_everyone": false,
"mentions": [],
"mention_roles": [],
"attachments": [],
"embeds": [],
"pinned": false,
"flags": 0,
"components": [],
"channel_type": 1
}In a reply, referenced_message is filled when the gateway saw the original recently;
otherwise it’s null, and GET /channels/{channel.id}/messages/{message.id} has it.
MESSAGE_UPDATE
The whole message after an edit, with edited_timestamp set and the gateway’s extra fields,
as in MESSAGE_CREATE. Here, the message above after Leo edited it:
{
"id": "1571350405442719744",
"channel_id": "1571350333212610562",
"type": 0,
"author": {
"id": "1571350327143452672",
"username": "leo",
"discriminator": "0",
"global_name": "Leo",
"avatar": null,
"banner": null,
"accent_color": null,
"public_flags": 0
},
"content": "<@1571350332965146624> what's the tide tomorrow?",
"timestamp": "2026-11-15T02:25:30.936Z",
"edited_timestamp": "2026-11-15T02:25:30.976Z",
"tts": false,
"mention_everyone": false,
"mentions": [
{
"id": "1571350332965146624",
"username": "lighthouse",
"discriminator": "0",
"global_name": "Lighthouse",
"avatar": null,
"banner": null,
"accent_color": null,
"public_flags": 0,
"bot": true,
"member": {
"nick": null,
"avatar": null,
"banner": null,
"roles": ["1571350334990995456"],
"joined_at": "2026-11-15T02:25:14.129Z",
"premium_since": null,
"deaf": false,
"mute": false,
"flags": 4,
"pending": false,
"communication_disabled_until": null
}
}
],
"mention_roles": [],
"attachments": [],
"embeds": [],
"pinned": false,
"flags": 0,
"components": [],
"channel_type": 0,
"guild_id": "1571350333212610560",
"member": {
"nick": null,
"avatar": null,
"banner": null,
"roles": ["1571350334701588480"],
"joined_at": "2026-11-15T02:25:13.778Z",
"premium_since": null,
"deaf": false,
"mute": false,
"flags": 0,
"pending": false,
"communication_disabled_until": null
}
}MESSAGE_DELETE
{
"id": "1571350405442719744",
"channel_id": "1571350333212610562",
"guild_id": "1571350333212610560"
}In a direct message, without guild_id.
MESSAGE_DELETE_BULK
Several messages of one channel deleted at once: a bot’s bulk delete, or Klang’s team removing an account’s messages. Only the IDs that were really deleted.
{
"ids": ["1571460891315945472", "1571460891357888512", "1571460891416608768"],
"channel_id": "1571460870625443842",
"guild_id": "1571460870625443840"
}Ban events
They need GUILD_MODERATION, and only reach bots that can ban or view the audit log in the
server. A ban from the app and one from a bot both send them.
GUILD_BAN_ADD
Someone was banned. They also leave the server, so a
GUILD_MEMBER_REMOVE comes first.
{
"guild_id": "1571460870625443840",
"user": {
"id": "1571460874375151616",
"username": "ivymwhneb9d2cq",
"discriminator": "0",
"global_name": "Ivy",
"avatar": null,
"banner": null,
"accent_color": null,
"public_flags": 0
}
}GUILD_BAN_REMOVE
A ban was lifted. The same fields.
Reaction events
emoji is a partial emoji: { "id": null, "name": "👍" } for a Unicode one, and id, name
and animated for a custom one. In direct messages, these events come without guild_id and
member.
MESSAGE_REACTION_ADD
member is the person who reacted, in a server. message_author_id is there when the gateway
saw the message recently.
{
"user_id": "1571350327143452672",
"message_id": "1571350346504359936",
"channel_id": "1571350333212610562",
"guild_id": "1571350333212610560",
"emoji": { "id": null, "name": "👍" },
"burst": false,
"type": 0,
"burst_colors": [],
"member": {
"nick": null,
"avatar": null,
"banner": null,
"roles": ["1571350334701588480"],
"joined_at": "2026-11-15T02:25:13.778Z",
"premium_since": null,
"deaf": false,
"mute": false,
"flags": 0,
"pending": false,
"communication_disabled_until": null,
"user": {
"id": "1571350327143452672",
"username": "leo",
"discriminator": "0",
"global_name": "Leo",
"avatar": null,
"banner": null,
"accent_color": null,
"public_flags": 0
}
},
"message_author_id": "1571350332965146624"
}MESSAGE_REACTION_REMOVE
{
"user_id": "1571350332965146624",
"message_id": "1571350339084636160",
"channel_id": "1571350333212610562",
"guild_id": "1571350333212610560",
"emoji": { "id": null, "name": "🌊" },
"burst": false,
"type": 0
}MESSAGE_REACTION_REMOVE_EMOJI
A moderator removed every reaction with one emoji.
{
"message_id": "1571350346504359936",
"channel_id": "1571350333212610562",
"guild_id": "1571350333212610560",
"emoji": { "id": null, "name": "👍" }
}MESSAGE_REACTION_REMOVE_ALL
A moderator removed every reaction from a message.
{
"message_id": "1571350405551771648",
"channel_id": "1571350333212610562",
"guild_id": "1571350333212610560"
}Pin events
CHANNEL_PINS_UPDATE
A message was pinned or unpinned in a channel the bot sees. last_pin_timestamp is when the
message was pinned; after an unpin it’s null, because Klang’s event doesn’t say which pin is
now the latest. In a direct message there’s no guild_id.
{
"channel_id": "1575627021880139778",
"guild_id": "1575627021880139776",
"last_pin_timestamp": "2026-11-26T21:39:16.954Z"
}Emoji and sticker events
GUILD_EMOJIS_UPDATE
A server’s emoji was created, renamed or deleted: the whole list, as it is now.
{
"guild_id": "1575627021880139776",
"emojis": [
{
"id": "1575627027156574208",
"name": "conserje_jefe",
"animated": false,
"roles": [],
"require_colons": true,
"managed": false,
"available": true
}
]
}GUILD_STICKERS_UPDATE
The same for stickers. A sticker’s tags is its emoji. description comes null here: read it
with GET /guilds/{guild.id}/stickers.
{
"guild_id": "1575627021880139776",
"stickers": [
{
"id": "1575627025684373504",
"name": "Hola",
"description": null,
"tags": "🙋",
"type": 2,
"format_type": 1,
"available": true,
"guild_id": "1575627021880139776"
},
{
"id": "1575627026003140608",
"name": "Adios",
"description": null,
"tags": "👋",
"type": 2,
"format_type": 1,
"available": true,
"guild_id": "1575627021880139776"
}
]
}Poll events
MESSAGE_POLL_VOTE_ADD
Someone voted an answer. One event per answer: a vote for two answers sends two.
{
"user_id": "1575627018705051648",
"channel_id": "1575627021880139778",
"message_id": "1575627028943347712",
"guild_id": "1575627021880139776",
"answer_id": 1
}MESSAGE_POLL_VOTE_REMOVE
Someone took a vote back. Changing a vote sends this first, then a MESSAGE_POLL_VOTE_ADD.
{
"user_id": "1575627018705051648",
"channel_id": "1575627021880139778",
"message_id": "1575627028943347712",
"guild_id": "1575627021880139776",
"answer_id": 1
}AutoMod events
These only reach bots with Manage server in the server.
AUTO_MODERATION_RULE_CREATE
A rule was created, by a person or a bot: the whole rule.
AUTO_MODERATION_RULE_UPDATE and AUTO_MODERATION_RULE_DELETE carry the rule the same way, as
it ended up or as it was. Rules of Klang’s own types (links, invites) send nothing.
{
"id": "1575627029790597120",
"guild_id": "1575627021880139776",
"name": "Sin palabrotas",
"creator_id": "1575627025013284864",
"event_type": 1,
"trigger_type": 1,
"trigger_metadata": {
"keyword_filter": ["*prohibido*"],
"regex_patterns": [],
"allow_list": []
},
"actions": [
{
"type": 1,
"metadata": {}
},
{
"type": 2,
"metadata": {
"channel_id": "1575627021880139778"
}
}
],
"enabled": true,
"exempt_roles": [],
"exempt_channels": []
}AUTO_MODERATION_ACTION_EXECUTION
A rule’s action ran on what someone wrote: one event per action. content is empty without
MESSAGE_CONTENT. matched_keyword is the rule’s word that matched, and matched_content is
always null. There’s no message_id: Klang checks a message before it exists.
{
"guild_id": "1575627021880139776",
"action": {
"type": 1,
"metadata": {}
},
"rule_id": "1575627029790597120",
"rule_trigger_type": 1,
"user_id": "1575627022169546752",
"channel_id": "1575627021880139778",
"content": "",
"matched_keyword": "*prohibido*",
"matched_content": null
}Audit log events
GUILD_AUDIT_LOG_ENTRY_CREATE
A new entry in the server’s audit log, for bots with GUILD_MODERATION and View audit log.
It’s the entry as GET /guilds/{guild.id}/audit-logs
lists it, with guild_id, and only for the actions that list has: what Klang records without a
number in Discord sends nothing. It doesn’t carry the user: user_id is who did it, and
null when nobody did, such as a change made with a webhook’s token. Ana let the bot into a
channel:
{
"id": "1575719352409391104",
"user_id": "1575718768511942656",
"target_id": "1575719352073846784",
"action_type": 14,
"options": { "id": "1575719327113543680", "type": "1" },
"changes": [
{ "key": "allow", "new_value": "66560" },
{ "key": "deny", "new_value": "0" }
],
"guild_id": "1575719326438260736"
}The bot created a webhook, with a reason:
{
"id": "1575719330280243200",
"user_id": "1575719327113543680",
"target_id": "1575719330175385600",
"action_type": 50,
"reason": "Tide alerts for the harbor",
"guild_id": "1575719326438260736"
}Webhook events
WEBHOOKS_UPDATE
A webhook of a channel was created, changed or deleted, by a person, a bot, or someone with its
URL. It says where, not what: list the channel’s webhooks to see them
(Webhooks). Moving a webhook sends one for each
channel. It goes to bots with GUILD_WEBHOOKS that see the channel.
{ "guild_id": "1575719326438260736", "channel_id": "1575719326438260738" }User events
USER_UPDATE
The bot’s own user changed: here its app was renamed in the portal. It needs no intent. The
bot’s member in each server also changes, so a GUILD_MEMBER_UPDATE follows for each.
{
"id": "1571350332965146624",
"username": "lighthouse",
"discriminator": "0",
"global_name": "Lighthouse Bot",
"avatar": null,
"banner": null,
"accent_color": null,
"public_flags": 0,
"bot": true,
"flags": 0,
"verified": true,
"mfa_enabled": false,
"email": null,
"locale": "en-US"
}Interaction events
INTERACTION_CREATE
Someone used one of the bot’s commands, is typing an option with autocomplete, pressed a button
or chose in a select menu of one of its messages, or sent one of its modals. The d is an
interaction; answer it as in
Responding to interactions, Buttons, menus and layouts
and Modals.
- It needs no intent.
- It goes to one connection of the app: the newest one. If the bot has two connections open, the older one doesn’t get it.
- It doesn’t arrive at all when the app has an interactions endpoint URL: the interaction goes there instead.
- It’s kept for a resume, like any event. A bot that isn’t connected misses it, and the person sees that the application didn’t respond.
Leo used /tide harbor:north-pier days:2 units:m:
{
"id": "1575120625984638976",
"application_id": "1575120256797806592",
"type": 2,
"data": {
"id": "1575120622050381825",
"name": "tide",
"type": 1,
"options": [
{ "name": "harbor", "type": 3, "value": "north-pier" },
{ "name": "days", "type": 4, "value": 2 },
{ "name": "units", "type": 3, "value": "m" }
]
},
"token": "UQ5TT0YnqlxErb6sZB1zIsJHh7PPf1XxkveIxXAxm_foonW_SaiyU7PzXNCaes7QLESGOQaPdQ3iyvA7FRA0gBR-2VxDJRaN",
"version": 1,
"app_permissions": "563261442739777",
"locale": "en-US",
"entitlements": [],
"attachment_size_limit": 26214400,
"guild_id": "1575120255329800192",
"guild": { "id": "1575120255329800192", "locale": "en-US", "features": [] },
"guild_locale": "en-US",
"channel": {
"id": "1575120255329800194",
"type": 0,
"name": "general",
"guild_id": "1575120255329800192",
"parent_id": null,
"nsfw": false,
"flags": 0,
"permissions": "563261442739777",
"position": 0,
"last_message_id": "1575120255891836928",
"rate_limit_per_user": 0,
"topic": null
},
"channel_id": "1575120255329800194",
"member": {
"nick": null,
"avatar": null,
"banner": null,
"roles": [],
"joined_at": "2026-11-25T12:05:33.297Z",
"premium_since": null,
"deaf": false,
"mute": false,
"flags": 0,
"pending": false,
"communication_disabled_until": null,
"user": {
"id": "1575120252091797504",
"username": "leo",
"discriminator": "0",
"global_name": "Leo",
"avatar": null,
"banner": null,
"accent_color": null,
"public_flags": 0
},
"permissions": "563261442739777"
},
"authorizing_integration_owners": { "0": "1575120255329800192" },
"context": 0
}An autocomplete has type 4, and the option being typed comes with focused:
{
"id": "1575120625670066176",
"application_id": "1575120256797806592",
"type": 4,
"data": {
"id": "1575120622050381825",
"name": "tide",
"type": 1,
"options": [{ "name": "harbor", "type": 3, "value": "no", "focused": true }]
}
}A button press has type 3, its custom_id in data, and the message the button is on
(shortened here):
{
"id": "1575619367957962752",
"application_id": "1575618985764593664",
"type": 3,
"data": { "custom_id": "role:sailor", "component_type": 2 },
"message": {
"id": "1575619367794384896",
"channel_id": "1575618985164808194",
"type": 0,
"content": "Pick your harbor roles:",
"flags": 0,
"components": [{ "type": 1, "id": 1, "components": ["…"] }]
}
}A submitted modal has type 5, and in data the modal’s custom_id and what was written and
chosen:
{
"id": "1575619372097740800",
"application_id": "1575618985764593664",
"type": 5,
"data": {
"custom_id": "sighting",
"components": [
{ "type": 10, "id": 1 },
{
"type": 18,
"id": 2,
"component": { "type": 4, "id": 3, "custom_id": "boat", "value": "Sea Swallow" }
},
{
"type": 18,
"id": 4,
"component": { "type": 3, "id": 5, "custom_id": "where", "values": ["north-pier"] }
}
]
}
}The rest of their fields are the same as above. The bot’s answers come back to it as ordinary
MESSAGE_CREATE events, with interaction_metadata (of type 20 or 23 for a command, 0 for
a component or a modal), and an update of a component’s message as a MESSAGE_UPDATE, if it has
the intent for them. Ephemeral answers never do: they aren’t messages of the channel.
Close codes
When Klang closes the connection, the close code says why, with no reason text. What each code means, and whether to reconnect after it, is in Gateway.