KlangDocs

    Open Klang

    Bot API reference

    View as Markdown

    Bot API reference

    Every route of Klang’s bot API and every event of its gateway, with the fields Klang sends, real examples, the errors and the rate limits. How requests and answers work across the whole API.

    How to use this reference

    These pages describe what Klang’s bot API does today, route by route and event by event. Each example is a real answer from a Klang server, shortened in places: long lists keep one or two items. The IDs in them are real Klang IDs, in the form bots see them.

    • Users and the app: the gateway’s address, the bot itself, other people, its app, its servers and direct messages.
    • Servers: a server, its channels, roles and members.
    • Channels: one channel, thread or direct message.
    • Messages: reading, sending, editing and deleting messages, reactions and “is typing”.
    • Moderation: kicking, banning, timeouts, nicknames, roles and bulk deletes.
    • Managing a server: channels, their permission overwrites, roles, invites and the audit log.
    • Threads: starting, changing and deleting threads, following them, and the active and archived ones.
    • Pins, polls, emojis, stickers and AutoMod: pinning messages, polls and their votes, a server’s emojis and stickers, and its AutoMod rules.
    • Webhooks: creating, listing, changing, moving and deleting a server’s webhooks.
    • Commands: registering, editing and deleting slash, user and message commands, and reading who can use them.
    • Interactions: answering an interaction (a message, an update of a component’s message, a modal), follow-ups, and editing and deleting the answers.
    • Components: buttons, select menus, layout components and the fields of a modal, with their limits.
    • Objects: every object those routes and events return, field by field.
    • Gateway events: opcodes, the first frames and every event Klang dispatches.
    • Errors: the error body and every code Klang sends.

    For the routes and events Klang doesn’t have yet, see the compatibility table. The two pages list the same routes; if you find they disagree, tell us at hi@klang.gg.

    Base URL and versions

    URL
    https://api.klang.gg/api/v10

    /api/v9 answers the same routes in the same way, for libraries that still ask for it. Any other version, or a path outside the bot API, answers 404.

    Authentication

    Every route except GET /gateway, the webhook routes and the answers to an interaction needs the bot’s token in the Authorization header, after the word Bot and a space:

    Shell
    curl https://api.klang.gg/api/v10/users/@me \
      -H "Authorization: Bot $KLANG_BOT_TOKEN"

    A missing, malformed, reset or suspended token answers 401 with code 0. So do a Bearer token and the cookie of a Klang session: the bot API only takes bot tokens, and a bot token doesn’t open the API the Klang app uses.

    Requests

    • Bodies are JSON, sent with Content-Type: application/json. The routes that take files also take multipart/form-data, with the JSON in payload_json (see Sending files). A body that isn’t valid JSON answers 50109. An empty body counts as no body, whatever its Content-Type.
    • IDs travel as strings. Klang also reads them as JSON numbers, keeping all 19 digits, because some libraries send them that way.
    • Both kinds of ID work. Klang reads the IDs bots get and the unshifted ones its own app shows (see IDs), in paths, query strings and bodies.
    • Fields Klang doesn’t know are ignored, so a body built for Discord’s API goes through. The route’s section says which known fields are accepted and do nothing.
    • Booleans in a query string are the words true and false.
    • Bad input answers 50035, with an errors object that points at each field. See Errors.

    Responses

    • JSON, with Content-Type: application/json exactly, without a charset. Routes that change something and have nothing to return answer 204 with an empty body.
    • Field names are snake_case and IDs are strings, as in Discord’s API.
    • A field Klang has no data for is still there when Discord’s API always sends it, with its empty value: null, false, 0, "" or []. The tables in Objects say which fields are always empty in Klang.
    • Optional fields are left out when they don’t apply, such as reactions on a message nobody reacted to, or bot on a person.
    • Dates are ISO 8601 strings in UTC, with milliseconds: 2026-11-15T02:25:15.115Z.
    • Permissions are decimal strings of Discord’s bits. See Permissions.
    • Images (avatars, icons, banners) are hashes. Libraries build their addresses on https://media.klangcdn.com: see Images.

    Routes

    Route Page Bucket
    GET /gateway Users and the app —
    GET /gateway/bot Users and the app —
    GET /users/@me Users and the app —
    GET /users/{user.id} Users and the app read-users
    GET /applications/@me, GET /oauth2/applications/@me Users and the app —
    PATCH /applications/@me Users and the app interactions-url-check
    GET /users/@me/guilds Users and the app read-guild
    DELETE /users/@me/guilds/{guild.id} Users and the app —
    POST /users/@me/channels Users and the app dm-create
    GET /guilds/{guild.id} Servers read-guild
    GET /guilds/{guild.id}/channels Servers read-guild
    GET /guilds/{guild.id}/roles Servers read-guild
    GET /guilds/{guild.id}/members Servers read-members
    GET /guilds/{guild.id}/members/{user.id} Servers read-users
    GET /channels/{channel.id} Channels read-message
    GET /channels/{channel.id}/messages Messages read-messages
    GET /channels/{channel.id}/messages/{message.id} Messages read-message
    POST /channels/{channel.id}/messages Messages message
    PATCH /channels/{channel.id}/messages/{message.id} Messages message-edit
    DELETE /channels/{channel.id}/messages/{message.id} Messages message-edit
    POST /channels/{channel.id}/typing Messages typing
    PUT /channels/{channel.id}/messages/{message.id}/reactions/{emoji}/@me Messages reaction
    DELETE /channels/{channel.id}/messages/{message.id}/reactions/{emoji}/@me Messages —
    POST /channels/{channel.id}/messages/bulk-delete Moderation bulk-delete
    DELETE /guilds/{guild.id}/members/{user.id} Moderation —
    PATCH /guilds/{guild.id}/members/{user.id} Moderation nickname, timeout
    PATCH /guilds/{guild.id}/members/@me Moderation nickname
    PUT, DELETE /guilds/{guild.id}/members/{user.id}/roles/{role.id} Moderation —
    PUT, DELETE /guilds/{guild.id}/bans/{user.id} Moderation —
    GET /guilds/{guild.id}/bans, GET /guilds/{guild.id}/bans/{user.id} Moderation read-bans, read-users
    POST /guilds/{guild.id}/channels Managing a server channel-create
    PATCH /channels/{channel.id} Managing a server, Threads manage-channels, thread-manage
    DELETE /channels/{channel.id} Managing a server manage-channels, thread-manage
    PATCH /guilds/{guild.id}/channels Managing a server manage-channels
    PUT, DELETE /channels/{channel.id}/permissions/{overwrite.id} Managing a server manage-channels
    POST /guilds/{guild.id}/roles, PATCH, DELETE …/roles/{role.id} Managing a server manage-roles
    PATCH /guilds/{guild.id}/roles Managing a server manage-roles
    POST /channels/{channel.id}/invites Managing a server invite-create
    GET /channels/{channel.id}/invites, GET /guilds/{guild.id}/invites Managing a server read-invites
    GET /invites/{invite.code} Managing a server invite-preview
    DELETE /invites/{invite.code} Managing a server —
    GET /guilds/{guild.id}/audit-logs Managing a server read-audit-log
    POST /channels/{channel.id}/messages/{message.id}/threads, POST /channels/{channel.id}/threads Threads thread-create
    PUT, DELETE /channels/{thread.id}/thread-members/@me Threads thread-manage
    GET /channels/{thread.id}/thread-members, …/thread-members/{user.id} Threads read-members, read-users
    GET /guilds/{guild.id}/threads/active Threads read-guild
    GET /channels/{channel.id}/threads/archived/public Threads thread-list
    GET /channels/{channel.id}/messages/pins Pins, polls, emojis, stickers and AutoMod read-messages
    PUT, DELETE /channels/{channel.id}/messages/pins/{message.id} Pins, polls, emojis, stickers and AutoMod message-edit
    GET /channels/{channel.id}/polls/{message.id}/answers/{answer.id} Pins, polls, emojis, stickers and AutoMod poll-voters
    POST /channels/{channel.id}/polls/{message.id}/expire Pins, polls, emojis, stickers and AutoMod message-edit
    GET /guilds/{guild.id}/emojis, …/emojis/{emoji.id} Pins, polls, emojis, stickers and AutoMod read-guild
    POST /guilds/{guild.id}/emojis, PATCH, DELETE …/emojis/{emoji.id} Pins, polls, emojis, stickers and AutoMod emojis
    GET /guilds/{guild.id}/stickers, …/stickers/{sticker.id} Pins, polls, emojis, stickers and AutoMod read-guild
    POST /guilds/{guild.id}/stickers, PATCH, DELETE …/stickers/{sticker.id} Pins, polls, emojis, stickers and AutoMod stickers
    GET /guilds/{guild.id}/auto-moderation/rules, …/rules/{rule.id} Pins, polls, emojis, stickers and AutoMod read-guild
    POST /guilds/{guild.id}/auto-moderation/rules, PATCH, DELETE …/rules/{rule.id} Pins, polls, emojis, stickers and AutoMod automod
    GET /channels/{channel.id}/webhooks, GET /guilds/{guild.id}/webhooks Webhooks read-webhooks
    POST /channels/{channel.id}/webhooks Webhooks webhook-manage
    GET /webhooks/{webhook.id} Webhooks read-webhooks
    PATCH, DELETE /webhooks/{webhook.id} Webhooks webhook-manage
    GET /applications/{app.id}/commands, and per server Commands read-commands
    POST /applications/{app.id}/commands, and per server Commands commands-write
    PUT /applications/{app.id}/commands, and per server Commands commands-write
    GET /applications/{app.id}/commands/{command.id}, and per server Commands read-commands
    PATCH /applications/{app.id}/commands/{command.id}, and per server Commands commands-write
    DELETE /applications/{app.id}/commands/{command.id}, and per server Commands commands-write
    GET /applications/{app.id}/guilds/{guild.id}/commands/permissions, and of one command Commands read-commands
    POST /interactions/{interaction.id}/{interaction.token}/callback Interactions None
    POST /webhooks/{app.id}/{interaction.token} Interactions interaction-webhook
    GET, PATCH, DELETE /webhooks/{app.id}/{interaction.token}/messages/{message.id} Interactions interaction-webhook

    Rate limits

    Every request counts against the global limit: 50 per second per bot, or per IP address for requests without a valid token. Routes with a bucket count against it too. A dash in the table above means the global limit only. The answers to an interaction are the exception: they don’t count against the global limit at all (“None” above), and the follow-ups and edits only count against interaction-webhook.

    Bucket Limit Counted per
    message 5 every 5 seconds Bot and channel
    message-edit 10 every 10 seconds Bot, for edits and deletes together
    reaction 10 every 10 seconds Bot
    typing 5 every 10 seconds Bot and channel
    dm-create 10 every 10 minutes Bot, only when a new DM is opened
    read-members 10 every 10 seconds Bot, whichever server
    read-messages 10 every 5 seconds Bot, whichever channel
    read-message 50 every 10 seconds Bot, for a message or a channel
    read-guild 10 every 10 seconds Bot, for a server, its channels and roles, and its servers
    read-users 20 every 5 seconds Bot, for a user, a member or one ban
    bulk-delete 5 every 10 seconds Bot
    nickname 20 every 10 minutes Bot and server
    timeout 30 every 10 minutes Bot, for timing out and lifting timeouts
    read-bans 10 every 10 seconds Bot, for the list of bans
    read-commands 20 every 10 seconds Bot, for its commands and their permissions, wherever
    commands-write 20 every 20 seconds App, for creating, replacing, editing and deleting commands, global and per server together
    interaction-webhook 5 every 2 seconds Interaction, for its follow-ups and its messages
    manage-channels 20 every 10 seconds Bot and server, for changing, ordering and deleting channels and their overwrites
    manage-roles 20 every 10 seconds Bot and server, for creating, changing, ordering and deleting roles
    channel-create 20 every 10 minutes Server, shared with the people in the app
    invite-create 10 every 10 minutes Server, shared with the people in the app
    invite-preview 60 every minute Bot, for looking up an invite by its code
    read-invites 10 every 10 seconds Bot, for a channel’s and a server’s invites
    read-audit-log 10 every 10 seconds Bot, for the audit log
    thread-create 10 every 10 minutes Bot, for starting threads
    thread-manage 30 every minute Bot, for changing, deleting, joining and leaving threads
    thread-list 30 every minute Bot, for a channel’s archived threads
    interactions-url-check 10 every 10 minutes App, for each check of an interactions endpoint URL, from the portal or the API
    poll-voters 30 every minute Bot, for who voted in a poll
    emojis 30 every 10 minutes Server, shared with the people in the app
    stickers 30 every 10 minutes Server, shared with the people in the app
    automod 30 every 10 minutes Server, shared with the people in the app
    read-webhooks 10 every 10 seconds Bot, for a channel’s or a server’s webhooks and one webhook
    webhook-manage 20 every 10 minutes Bot, for creating, changing and deleting webhooks, as people have it; with a webhook’s token, per webhook

    The bucket names are ours, for these pages: the API sends an opaque ID in X-RateLimit-Bucket instead. Routes in the same bucket send the same ID. How the headers and the 429 answer work is in Limits and rate limits.

    A response from a route with a bucket carries its headers, even when it succeeds:

    HTTP
    HTTP/1.1 200 OK
    Content-Type: application/json
    X-RateLimit-Bucket: 88a32224e61b0e1dcbdee4406179cfd5
    X-RateLimit-Limit: 5
    X-RateLimit-Remaining: 4
    X-RateLimit-Reset: 1794709517.881
    X-RateLimit-Reset-After: 1.000

    Webhooks

    The webhook routes also answer under the bot API’s base, so libraries that build webhook URLs from it reach them. They don’t take a bot token: the webhook’s token in the path is the key.

    Route What it does
    POST /webhooks/{webhook.id}/{webhook.token} Posts a message. See Execute a webhook.
    GET /webhooks/{webhook.id}/{webhook.token} The webhook, without its token.
    PATCH, DELETE /webhooks/{webhook.id}/{webhook.token} Renames it, changes its avatar or deletes it. See With the webhook’s token.
    PATCH /webhooks/{webhook.id}/{webhook.token}/messages/{message.id} Edits a message that webhook posted.
    DELETE /webhooks/{webhook.id}/{webhook.token}/messages/{message.id} Deletes a message that webhook posted.
    POST /webhooks/{webhook.id}/{webhook.token}/github Takes GitHub’s events. See GitHub.

    They’re the same routes as https://api.klang.gg/api/webhooks/…, with the same bodies, limits and errors, which Webhooks documents. The IDs they return are the ones bots see.

    With your app’s ID and an interaction’s token instead of a webhook’s, the same paths send follow-ups and edit the answers to that interaction: see Interactions.