Bot API reference
Users and the app
The routes about the bot itself. Where its gateway is, its user, other people it shares a server with, its app and its interactions URL, the servers it’s in, leaving one, and opening a direct message.
Gateway address
GET /gatewayWhere bots connect. It’s the only route that works without a token.
- Rate limit: the global limit, per IP address.
{
"url": "wss://bot-gateway.klang.gg"
}Gateway for a bot
GET /gateway/botThe same address, with how many shards to use and how many sessions the bot can still start today.
- Rate limit: the global limit.
| Field | Type | Notes |
|---|---|---|
url |
string | The bot gateway’s address. |
shards |
integer | Always 1. |
session_start_limit.total |
integer | Identify frames a bot can send per UTC day: 1000. |
session_start_limit.remaining |
integer | How many are left today. |
session_start_limit.reset_after |
integer | Milliseconds until the count starts again, at midnight UTC. |
session_start_limit.max_concurrency |
integer | Always 1: one Identify at a time, every 5 seconds at most. |
{
"url": "wss://bot-gateway.klang.gg",
"shards": 1,
"session_start_limit": {
"total": 1000,
"remaining": 999,
"reset_after": 77684409,
"max_concurrency": 1
}
}The bot’s user
GET /users/@meThe bot’s own user, with the fields only the bot reads about
itself: flags, verified (always true), mfa_enabled (always false), email (always
null) and locale (always en-US).
- Rate limit: the global limit.
{
"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"
}Another user
GET /users/{user.id}A person or a bot, with what their profile shows to everyone. Klang only answers for users the bot shares a server or a direct message with; anyone else is an unknown user, whether they exist or not. See Looking up users.
- Rate limit:
read-users, 20 every 5 seconds per bot.
| Status | Code | When |
|---|---|---|
404 |
10013 |
The user doesn’t exist, or shares nothing with the bot. |
{
"id": "1571350327143452672",
"username": "leo",
"discriminator": "0",
"global_name": "Leo",
"avatar": null,
"banner": null,
"accent_color": null,
"public_flags": 0
}The bot’s app
GET /applications/@me
GET /oauth2/applications/@meBoth answer the same: the bot’s application, with its
owner and how many servers the bot is in. Libraries read it when they start, for the owner’s ID
and the app’s flags.
- Rate limit: the global limit.
{
"id": "1571350332965146624",
"name": "Lighthouse",
"icon": null,
"description": "Posts the tide tables every morning.",
"summary": "",
"bot_public": false,
"bot_require_code_grant": false,
"bot": {
"id": "1571350332965146624",
"username": "lighthouse",
"discriminator": "0",
"global_name": "Lighthouse",
"avatar": null,
"banner": null,
"accent_color": null,
"public_flags": 0,
"bot": true
},
"owner": {
"id": "1571350324312297472",
"username": "nora",
"discriminator": "0",
"global_name": "Nora",
"avatar": null,
"banner": null,
"accent_color": null,
"public_flags": 0
},
"verify_key": "682781a2f47cfbc91c26970c848641a3a7e2773c0d0d4e9d1153f75c19eb797a",
"team": null,
"flags": 557056,
"flags_new": "557056",
"redirect_uris": [],
"interactions_endpoint_url": null,
"approximate_guild_count": 1
}Here flags is 557056: GATEWAY_GUILD_MEMBERS_LIMITED (1 << 15) and
GATEWAY_MESSAGE_CONTENT_LIMITED (1 << 19), the two privileged intents switched on in the
portal. verify_key is the public key that checks HTTP interactions.
Set the interactions URL
PATCH /applications/@meSets or removes the app’s interactions endpoint URL, the same as the
portal’s General tab. A URL is saved only if it passes
the check: a signed PING has to get 200
with {"type": 1}, and a badly signed one 401. Answers with the bot’s
application.
It’s the only field Klang changes here: the description, the icon and the rest are edited in the portal, and sending any of them is an error, so your bot never thinks it changed something that didn’t.
- Rate limit: the global limit and, when there’s a URL,
interactions-url-check, 10 every 10 minutes per app (shared with the portal).
| Field | Type | Notes |
|---|---|---|
interactions_endpoint_url |
string or null | Up to 512 characters. null or "" goes back to INTERACTION_CREATE on the gateway. |
| Status | Code | When |
|---|---|---|
400 |
50035 |
The URL didn’t pass the check: the error is on interactions_endpoint_url, with a message that says which part failed. Or the body has another field. |
{
"interactions_endpoint_url": "https://tides.example.workers.dev/"
}The bot’s servers
GET /users/@me/guildsThe servers the bot is in, as short server objects, in ascending order of ID.
- Rate limit:
read-guild, 10 every 10 seconds per bot.
| Query | Type | Notes |
|---|---|---|
before |
ID | Only servers with a smaller ID: the closest ones to it. |
after |
ID | Only servers with a bigger ID. If both are sent, after counts. |
limit |
integer, 1 to 200 | 200 by default. |
with_counts |
true or false |
Adds approximate_member_count and approximate_presence_count (people online now). |
Each item has id, name, icon, banner, owner (always false: a bot never owns a
server), permissions (what the bot can do in the server, from its roles, before any channel’s
overwrites) and features.
[
{
"id": "1571350333212610560",
"name": "Harbor",
"icon": null,
"banner": null,
"owner": false,
"permissions": "563261442739777",
"features": ["PIN_PERMISSION_MIGRATION_COMPLETE"],
"approximate_member_count": 3,
"approximate_presence_count": 1
}
]Leave a server
DELETE /users/@me/guilds/{guild.id}The bot leaves the server, as if someone with Manage server had removed it: its role goes
with it, and the server’s audit log shows the bot as the one who removed it. Answers 204.
The bot gets a GUILD_DELETE. To come back,
someone has to add it again.
- Rate limit: the global limit.
| Status | Code | When |
|---|---|---|
404 |
10004 |
The bot isn’t in it. |
Open a direct message
POST /users/@me/channelsOpens the direct message between the bot and a person, or returns the one they already have.
Answers with the DM channel; send messages to
its id. Opening one doesn’t send a CHANNEL_CREATE.
The person has to share a server with the bot and allow it in their privacy settings. See Direct messages.
- Rate limit:
dm-create, only when a new one is opened. Getting one that already exists is free.
| Field | Type | Notes |
|---|---|---|
recipient_id |
ID | Required. The person to write to. |
| Status | Code | When |
|---|---|---|
403 |
50007 |
No server in common, their settings don’t allow it, a block, the other user is a bot, or there’s no such user. Always the same code, so the reason stays private. |
400 |
0 |
The bot tried to open one with itself. |
{
"recipient_id": "1571350327143452672"
}{
"id": "1571350402322157569",
"recipients": [
{
"id": "1571350327143452672",
"username": "leo",
"discriminator": "0",
"global_name": "Leo",
"avatar": null,
"banner": null,
"accent_color": null,
"public_flags": 0
}
],
"last_message_id": null,
"flags": 0,
"type": 1,
"name": null
}