KlangDocs

    Open Klang

    Bot API reference

    View as Markdown

    Messages

    Reading, sending, editing and deleting messages, the bot’s own reactions and the “is typing” indicator. Every field of the request body, with the checks, limits and errors of each route.

    Before you read

    These routes work in server channels, threads and the bot’s direct messages. They go through the same checks as a person’s messages: the channel’s permissions, timeouts, slow mode, locked threads and the server’s AutoMod. The server’s verification level doesn’t apply to bots.

    A channel the bot can’t see answers 404 with 10003, as if it didn’t exist.

    Content and the MESSAGE_CONTENT intent

    If the app doesn’t have the Message content intent switched on in the developer portal, messages from a server come with content, embeds, attachments, components, sticker_items and poll empty. Three kinds keep them: the bot’s own messages, messages that mention it, and its direct messages. A reply’s referenced_message follows the same rule on its own. This is the same message read without the intent:

    JSON
    {
      "id": "1571350339084636160",
      "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": "",
      "timestamp": "2026-11-15T02:25:15.115Z",
      "edited_timestamp": null,
      "tts": false,
      "mention_everyone": false,
      "mentions": [],
      "mention_roles": [],
      "attachments": [],
      "embeds": [],
      "pinned": false,
      "flags": 0,
      "components": [],
      "reactions": [
        {
          "emoji": { "id": null, "name": "👋" },
          "count": 1,
          "count_details": { "burst": 0, "normal": 1 },
          "me": false,
          "me_burst": false,
          "burst_colors": []
        }
      ]
    }

    A page of messages

    HTTP
    GET /channels/{channel.id}/messages

    Up to 100 messages, the newest first. Deleted messages aren’t in it.

    • Needs: VIEW_CHANNEL.
    • Rate limit: read-messages, 10 every 5 seconds per bot, whichever channel.
    Query Type Notes
    before ID Messages older than this one.
    after ID Messages newer than this one.
    around ID Messages on both sides of this one, and the message itself.
    limit integer, 1 to 100 50 by default.

    Send one of before, after and around at most. Without any of them, the page starts at the newest message.

    Status Code When
    400 50035 More than one of before, after and around.
    404 10003 No such channel, or the bot can’t see it.

    GET /channels/1571350333212610562/messages?limit=2, the notice of a new thread and a poll:

    JSON
    [
      {
        "id": "1571350339420180482",
        "channel_id": "1571350333212610562",
        "type": 18,
        "author": {
          "id": "1571350324312297472",
          "username": "nora",
          "discriminator": "0",
          "global_name": "Nora",
          "avatar": null,
          "banner": null,
          "accent_color": null,
          "public_flags": 0
        },
        "content": "Saturday plans",
        "timestamp": "2026-11-15T02:25:15.195Z",
        "edited_timestamp": null,
        "tts": false,
        "mention_everyone": false,
        "mentions": [],
        "mention_roles": [],
        "attachments": [],
        "embeds": [],
        "pinned": false,
        "flags": 0,
        "components": [],
        "message_reference": {
          "type": 0,
          "channel_id": "1571350339420180480",
          "guild_id": "1571350333212610560"
        }
      },
      {
        "id": "1571350339235631104",
        "channel_id": "1571350333212610562",
        "type": 0,
        "author": {
          "id": "1571350324312297472",
          "username": "nora",
          "discriminator": "0",
          "global_name": "Nora",
          "avatar": null,
          "banner": null,
          "accent_color": null,
          "public_flags": 0
        },
        "content": "",
        "timestamp": "2026-11-15T02:25:15.151Z",
        "edited_timestamp": null,
        "tts": false,
        "mention_everyone": false,
        "mentions": [],
        "mention_roles": [],
        "attachments": [],
        "embeds": [],
        "pinned": false,
        "flags": 0,
        "components": [],
        "poll": {
          "question": { "text": "Boat trip on Saturday?" },
          "answers": [
            { "answer_id": 1, "poll_media": { "text": "Yes", "emoji": { "id": null, "name": "⛵" } } },
            { "answer_id": 2, "poll_media": { "text": "No" } }
          ],
          "expiry": "2026-11-16T02:25:15.153Z",
          "allow_multiselect": false,
          "layout_type": 1,
          "results": {
            "is_finalized": false,
            "answer_counts": [{ "id": 1, "count": 1, "me_voted": false }]
          }
        }
      }
    ]

    One message

    HTTP
    GET /channels/{channel.id}/messages/{message.id}

    One message of the channel.

    • Needs: VIEW_CHANNEL.
    • Rate limit: read-message, 50 every 10 seconds per bot.
    Status Code When
    404 10008 No such message in this channel, or it was deleted.
    404 10003 No such channel, or the bot can’t see it.
    JSON
    {
      "id": "1571350339084636160",
      "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": "Morning! Anyone checked the tide today?",
      "timestamp": "2026-11-15T02:25:15.115Z",
      "edited_timestamp": null,
      "tts": false,
      "mention_everyone": false,
      "mentions": [],
      "mention_roles": [],
      "attachments": [],
      "embeds": [],
      "pinned": false,
      "flags": 0,
      "components": [],
      "reactions": [
        {
          "emoji": { "id": null, "name": "👋" },
          "count": 1,
          "count_details": { "burst": 0, "normal": 1 },
          "me": false,
          "me_burst": false,
          "burst_colors": []
        }
      ]
    }

    Send a message

    HTTP
    POST /channels/{channel.id}/messages

    Posts a message as the bot and answers with it (200). The channel’s members get it at once, and so does the bot, as a MESSAGE_CREATE.

    • Needs: SEND_MESSAGES. In a thread, SEND_MESSAGES_IN_THREADS in its channel, and MANAGE_THREADS too if the thread is locked. A bot that’s timed out can’t write.
    • Slow mode applies, unless the bot has MANAGE_MESSAGES or MANAGE_CHANNELS there.
    • Rate limit: message, 5 every 5 seconds per channel.
    Field Type Notes
    content string Up to 4,000 characters. Mentions such as <@id> work with either kind of ID.
    embeds array of embeds Up to 10, with 6,000 characters in total. Only rich embeds are kept. See Embeds for each field’s limit.
    sticker_ids array of IDs One sticker at most, from a server the bot is in.
    poll object A poll, with Klang’s durations. See Send a poll.
    message_reference object Makes the message a reply. See below.
    allowed_mentions object Which mentions in content notify. See below.
    nonce string or integer Up to 25 characters. It comes back in the answer and in MESSAGE_CREATE.
    enforce_nonce boolean With true, the same nonce within 5 minutes returns the message already sent instead of posting it again.
    flags integer SUPPRESS_EMBEDS (1 << 2): no link previews. IS_COMPONENTS_V2 (1 << 15): the components are the message. Other bits are ignored.
    tts boolean Accepted and ignored. Klang doesn’t read messages aloud.
    components array Buttons and select menus in up to 5 action rows or, with IS_COMPONENTS_V2, up to 40 layout components. See Components.
    attachments array With files: id (the n of files[n]), filename. On an edit, the files that stay. See Sending files.

    A message needs content that isn’t blank, an embed, a sticker, a component or a file; otherwise it answers 50006. With IS_COMPONENTS_V2, it can’t have content, embeds, a sticker or a poll (50035): see Layout components. A poll goes on its own, without text, files or a sticker: see Send a poll.

    message_reference, for a reply:

    Field Type Notes
    message_id ID Required. A message of the same channel.
    channel_id ID Optional. If sent, it has to be this channel: a reply elsewhere answers 50035.
    guild_id ID Optional. Not checked.
    type integer Optional. Only 0, a reply. 1, a forward, answers 50035.
    fail_if_not_exists boolean true by default: replying to a message that isn’t there answers 10008. With false, the message goes out as a plain one.

    allowed_mentions can only take notifications away, never add them:

    Field Type Notes
    parse array of strings users, roles and everyone: the kinds of mention that notify. [] silences them all.
    users array of IDs Up to 100 people who may be notified. Together with users in parse, it answers 50035.
    roles array of IDs Up to 100 roles that may be notified. Together with roles in parse, it answers 50035.
    replied_user boolean Accepted and ignored: a reply always notifies the author of the message it answers.

    The mentions that don’t notify are left out of mentions and mention_roles in the answer.

    Status Code When
    400 50006 Nothing to show: no text, embed or sticker.
    400 50035 A field is wrong: text too long, two stickers, a forward, a reply to another channel…
    400 200000 The server’s AutoMod blocked it.
    403 50013 The bot can’t write here, or it’s timed out.
    403 160005 The thread is locked.
    403 50007 A direct message that’s closed: the person blocked the bot or no longer allows it.
    404 10003 No such channel, or the bot can’t see it.
    404 10008 The message it replies to isn’t there.
    404 10060 The sticker doesn’t exist or the bot can’t use it.
    429 20016 Slow mode: wait retry_after seconds. See Limits.

    A message with a mention, an embed and a nonce:

    JSON
    {
      "content": "High tide at 06:42, <@1571350327143452672>.",
      "nonce": "tide-0642",
      "enforce_nonce": true,
      "embeds": [
        {
          "title": "Tide table",
          "description": "Harbor, today",
          "color": 3113197,
          "fields": [
            { "name": "High", "value": "06:42 · 18:57", "inline": true },
            { "name": "Low", "value": "00:31 · 12:48", "inline": true }
          ],
          "footer": { "text": "Lighthouse" },
          "timestamp": "2026-11-15T06:00:00.000Z"
        }
      ],
      "allowed_mentions": { "parse": [] }
    }

    The answer. mentions is empty because allowed_mentions silenced Leo’s:

    JSON
    {
      "id": "1571350346504359936",
      "channel_id": "1571350333212610562",
      "type": 0,
      "author": {
        "id": "1571350332965146624",
        "username": "lighthouse",
        "discriminator": "0",
        "global_name": "Lighthouse",
        "avatar": null,
        "banner": null,
        "accent_color": null,
        "public_flags": 0,
        "bot": true
      },
      "content": "High tide at 06:42, <@1571350327143452672>.",
      "timestamp": "2026-11-15T02:25:16.884Z",
      "edited_timestamp": null,
      "tts": false,
      "mention_everyone": false,
      "mentions": [],
      "mention_roles": [],
      "attachments": [],
      "embeds": [
        {
          "type": "rich",
          "title": "Tide table",
          "description": "Harbor, today",
          "color": 3113197,
          "timestamp": "2026-11-15T06:00:00.000Z",
          "footer": { "text": "Lighthouse" },
          "fields": [
            { "name": "High", "value": "06:42 · 18:57", "inline": true },
            { "name": "Low", "value": "00:31 · 12:48", "inline": true }
          ]
        }
      ],
      "pinned": false,
      "flags": 0,
      "components": [],
      "nonce": "tide-0642"
    }

    A reply. The answer is a message of type 19, with message_reference and the message it answers in referenced_message (shortened here):

    JSON
    {
      "content": "Not yet, checking now.",
      "message_reference": { "message_id": "1571350339084636160" }
    }
    JSON
    {
      "id": "1571350346617606144",
      "channel_id": "1571350333212610562",
      "type": 19,
      "author": {
        "id": "1571350332965146624",
        "username": "lighthouse",
        "discriminator": "0",
        "global_name": "Lighthouse",
        "avatar": null,
        "banner": null,
        "accent_color": null,
        "public_flags": 0,
        "bot": true
      },
      "content": "Not yet, checking now.",
      "timestamp": "2026-11-15T02:25:16.911Z",
      "edited_timestamp": null,
      "tts": false,
      "mention_everyone": false,
      "mentions": [],
      "mention_roles": [],
      "attachments": [],
      "embeds": [],
      "pinned": false,
      "flags": 0,
      "components": [],
      "message_reference": {
        "type": 0,
        "message_id": "1571350339084636160",
        "channel_id": "1571350333212610562",
        "guild_id": "1571350333212610560"
      },
      "referenced_message": {
        "id": "1571350339084636160",
        "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": "Morning! Anyone checked the tide today?",
        "timestamp": "2026-11-15T02:25:15.115Z",
        "edited_timestamp": null,
        "tts": false,
        "mention_everyone": false,
        "mentions": [],
        "mention_roles": [],
        "attachments": [],
        "embeds": [],
        "pinned": false,
        "flags": 0,
        "components": []
      }
    }

    A sticker on its own: { "sticker_ids": ["1571350334407987200"] } answers a message with empty content and the sticker in sticker_items.

    Two errors, as Klang sends them:

    JSON
    {
      "code": 50035,
      "message": "The request body isn’t valid.",
      "errors": {
        "content": {
          "_errors": [{ "code": "BASE_TYPE_MAX_LENGTH", "message": "Up to 4000 characters." }]
        }
      }
    }
    JSON
    {
      "code": 20016,
      "message": "Slowmode is on in this channel. Wait a moment before sending again.",
      "retry_after": 30,
      "global": false
    }

    Edit a message

    HTTP
    PATCH /channels/{channel.id}/messages/{message.id}

    Changes a message the bot sent and answers with it (200). What the body doesn’t include stays as it was: sending only embeds keeps the text. Mentions are worked out again, but nobody is notified a second time.

    • Needs: the message is the bot’s, and the bot can still write in the channel (the same checks as sending, without slow mode). The new text goes through AutoMod. A body with only flags can suppress the link previews of someone else’s message too, with MANAGE_MESSAGES (see below).
    • Rate limit: message-edit, 10 every 10 seconds, shared with deleting.
    Field Type Notes
    content string or null Up to 4,000 characters. null empties the text.
    embeds array or null Replaces the bot’s embeds. [] or null removes them.
    allowed_mentions object As when sending.
    flags integer SUPPRESS_EMBEDS (1 << 2) removes the link previews; IS_COMPONENTS_V2 (1 << 15). Both can be set, never removed.
    components array Replaces the components. [] removes them. Without it, they stay.
    attachments array The files that stay, by id; new ones go in the form. Without it, they all stay. See Sending files.

    Without flags, the components are checked against the flag the message already has. A v2 message keeps the flag, so its edits can’t add content or embeds.

    A body with only flags (what message.suppressEmbeds() in discord.js and message.edit(suppress=True) in discord.py send) doesn’t count as an edit of the text: the message isn’t marked as edited and AutoMod doesn’t look at it. With SUPPRESS_EMBEDS, its link previews go and the bot’s own embeds stay. On someone else’s message, only this works, and only with MANAGE_MESSAGES in the channel. Once suppressed, the previews don’t come back: sending flags without the bit leaves the message as it is.

    Status Code When
    400 50006 The edit would leave the message with nothing to show: no text, embeds, components or files.
    400 50035 A field is wrong, or the edit would remove IS_COMPONENTS_V2.
    400 200000 The server’s AutoMod blocked the new text.
    403 50005 Someone else sent the message, and the body has more than flags.
    403 50013 The bot can no longer write in the channel, or lacks MANAGE_MESSAGES for someone else’s.
    403 160005 The thread is locked.
    404 10008 No such message in this channel.
    404 10003 No such channel, or the bot can’t see it.
    JSON
    {
      "content": "High tide at 06:44, <@1571350327143452672>."
    }

    The answer has the new text, the embeds it already had, an edited_timestamp, and Leo in mentions: this body didn’t send allowed_mentions, so the mention counts.

    JSON
    {
      "id": "1571350346504359936",
      "channel_id": "1571350333212610562",
      "type": 0,
      "author": {
        "id": "1571350332965146624",
        "username": "lighthouse",
        "discriminator": "0",
        "global_name": "Lighthouse",
        "avatar": null,
        "banner": null,
        "accent_color": null,
        "public_flags": 0,
        "bot": true
      },
      "content": "High tide at 06:44, <@1571350327143452672>.",
      "timestamp": "2026-11-15T02:25:16.884Z",
      "edited_timestamp": "2026-11-15T02:25:17.337Z",
      "tts": false,
      "mention_everyone": false,
      "mentions": [
        {
          "id": "1571350327143452672",
          "username": "leo",
          "discriminator": "0",
          "global_name": "Leo",
          "avatar": null,
          "banner": null,
          "accent_color": null,
          "public_flags": 0
        }
      ],
      "mention_roles": [],
      "attachments": [],
      "embeds": [
        {
          "type": "rich",
          "title": "Tide table",
          "description": "Harbor, today",
          "color": 3113197,
          "timestamp": "2026-11-15T06:00:00.000Z",
          "footer": { "text": "Lighthouse" },
          "fields": [
            { "name": "High", "value": "06:42 · 18:57", "inline": true },
            { "name": "Low", "value": "00:31 · 12:48", "inline": true }
          ]
        }
      ],
      "pinned": false,
      "flags": 0,
      "components": []
    }

    Delete a message

    HTTP
    DELETE /channels/{channel.id}/messages/{message.id}

    Deletes a message and answers 204. Everyone in the channel gets a MESSAGE_DELETE.

    • Needs: the message is the bot’s, or the bot has MANAGE_MESSAGES in the channel.
    • Rate limit: message-edit, shared with editing.
    Status Code When
    403 50013 Someone else’s message, without MANAGE_MESSAGES.
    404 10008 No such message in this channel.
    404 10003 No such channel, or the bot can’t see it.

    Is typing

    HTTP
    POST /channels/{channel.id}/typing

    Shows the people in the channel that the bot is typing. Answers 204. Klang doesn’t send typing events to bots yet.

    • Needs: SEND_MESSAGES.
    • Rate limit: typing, 5 every 10 seconds per channel.
    Status Code When
    403 50013 The bot can’t write here.
    404 10003 No such channel, or the bot can’t see it.

    Add a reaction

    HTTP
    PUT /channels/{channel.id}/messages/{message.id}/reactions/{emoji}/@me

    Adds the bot’s reaction and answers 204. If the bot had already reacted with that emoji, nothing changes and it still answers 204.

    {emoji} goes URL-encoded in the path:

    • a Unicode emoji as it is: %F0%9F%8C%8A for 🌊;
    • a custom emoji as name:id: anchor:1571350334105997312, encoded as anchor%3A1571350334105997312. a:name:id works too. The bot can use the emojis of the servers it’s in.

    The bot needs ADD_REACTIONS. The route’s bucket is reaction, 10 every 10 seconds.

    Status Code When
    400 10014 {emoji} isn’t a Unicode emoji or name:id.
    400 30010 The message already has 20 different reactions.
    403 50013 The bot can’t react here.
    404 10014 A custom emoji the bot can’t use.
    404 10008 No such message in this channel.
    404 10003 No such channel, or the bot can’t see it.

    Remove a reaction

    HTTP
    DELETE /channels/{channel.id}/messages/{message.id}/reactions/{emoji}/@me

    Removes the bot’s own reaction and answers 204, also when it wasn’t there. {emoji} is written as when adding it.

    • Needs: VIEW_CHANNEL. A bot can always take its own reaction back.
    • Rate limit: the global limit.
    Status Code When
    400 10014 {emoji} isn’t a Unicode emoji or name:id.
    404 10003 No such channel, or the bot can’t see it.