KlangDocs

    Open Klang

    Bots

    View as Markdown

    Differences from Discord’s API

    Where Klang behaves differently from Discord’s API version 10, and why. IDs, permissions, error codes, direct messages, looking up users, messages, moderation, managing a server, webhooks, threads, commands and interactions, components and modals, verification, links, and what Klang doesn’t have.

    In short

    Klang implements the parts of Discord’s API version 10 that match what Klang has, with the same routes, field names, numbers and error codes, so libraries don’t notice the difference. Where Klang works differently underneath, the API keeps Discord’s shape and this page says what changes. For which routes and events exist, see the compatibility table.

    IDs

    Klang’s IDs are snowflakes, like Discord’s: 64-bit numbers sent as strings, with the time they were created in their first 42 bits. Klang’s clock starts on 1 January 2025, though, and Discord’s on 1 January 2015. Read with Discord’s epoch, a raw Klang ID would look ten years older than it is, and libraries use that date for a lot: an account’s age, which messages are too old to delete in bulk, the latency a ping command prints.

    So every ID the bots’ API gives out is shifted by a constant:

    URL
    1323802873036800000 = (1735689600000 − 1420070400000) << 22

    That is the ten years between the two epochs, in milliseconds, moved to where a snowflake keeps its time. The rest of the ID doesn’t change. What it means for you:

    • Dates come out right. Your library’s createdAt (or created_at, or getTimeCreated()) gives the real moment, with no change on your side.
    • Use the IDs you get as they are. Every ID in the REST API, the gateway and the text of messages (<@id>, <#id>, <@&id>, <:name:id>) is already shifted, and every ID you send back is read the same way.
    • “Copy ID” in Klang copies the same ID your bot sees, for servers, channels, threads, messages and people. Paste it in your bot’s settings and it matches.
    • The app’s address bar shows a different number for the same server or channel: the one without the shift. Links with either number work in Klang, and the API also takes the unshifted number if one reaches it.

    To get a creation date by hand, read the ID with Discord’s epoch:

    const createdAt = new Date(Number((BigInt(snowflake) >> 22n) + 1420070400000n));
    from datetime import datetime, timezone
    
    created_at = datetime.fromtimestamp(((int(snowflake) >> 22) + 1420070400000) / 1000, timezone.utc)

    Permissions

    Bots see and send permissions as Discord’s bit numbers, everywhere: in the install link, in roles, in channel overwrites and in a server’s permissions. Klang has its own set of permissions with other numbers, and translates both ways. Every Klang permission has a match in Discord’s set. The other way round, a few need explaining:

    • Bits made up from Klang’s. Some of Discord’s permissions aren’t separate in Klang. They’re given whenever the Klang permission behind them is:

      Discord’s permission Given when the bot has, in Klang
      EMBED_LINKS Send messages (link previews need nothing more)
      READ_MESSAGE_HISTORY View channel (seeing a channel includes its history)
      USE_EXTERNAL_EMOJIS Always: anyone can use emojis from servers they’re in
      USE_VAD Speak
      SEND_POLLS Send messages
      CREATE_GUILD_EXPRESSIONS Manage expressions
      BYPASS_SLOWMODE Manage messages or Manage channels
    • STREAM covers two Klang permissions: turning the camera on and sharing the screen. A bot sees STREAM if either is allowed, and asking for STREAM asks for both.

    • Permissions for things Klang doesn’t have (stages, events, soundboard, private threads, text-to-speech and others) are kept as they were sent, so a bot that writes a number reads the same number back. They never allow anything in Klang.

    • MENTION_EVERYONE lets the bot notify @everyone and mention roles that aren’t mentionable. Klang has no @here.

    Channel overwrites come flattened. In Klang, a channel inside a category takes the category’s permissions and then its own on top. Discord’s model has only the channel’s overwrites. So the permission_overwrites your bot reads for a channel are the category’s and the channel’s merged into one list that gives the same result. When a perfect match isn’t possible, the list errs on the side of giving less. Permissions Klang computes for you, such as permissions in GET /users/@me/guilds, are always exact.

    Errors

    Errors have Discord’s shape, { "code": …, "message": "…" }, with errors for invalid fields, and use Discord’s codes where Klang has the same situation. Some answers differ on purpose:

    Situation Klang answers Why
    A channel that exists but the bot can’t see 404, 10003 Unknown channel Not 403 50001: Klang doesn’t confirm that a hidden channel exists.
    A user the bot shares no server or DM with 404, 10013 Unknown user See Looking up users.
    Editing a message someone else sent 403, 50005 As in Discord, even when the bot could delete it.
    A bot that’s timed out writes 403, 50013 Missing permissions Timing out takes permissions away, as in Discord.
    The server’s AutoMod blocks a message 400, 200000 Bot messages go through AutoMod like anyone’s.
    A server’s 200 new commands a day are used up 400, 30034 Not 429: libraries retry a 429, and this one waits until midnight UTC.
    Slow mode 429, 20016, with retry_after See Limits.
    The DM is closed (see Direct messages) 403, 50007 The same code for every reason, as in Discord.
    A route Klang doesn’t have 404, 0, "404: Not Found" Never a 500.
    A wrong, reset or suspended token 401, 0, "401: Unauthorized"
    A Klang error with no match in Discord’s list Its usual status, 0 and Klang’s message Klang never invents a number in Discord’s range.

    Direct messages

    A bot can only talk in private with people it shares a server with, and only if they allow it. Whether they do depends on their Who can send you direct messages setting:

    • Everyone or People you share a server with: the bot can open a DM with them, and they with it.
    • Friends only: no. A bot can’t be anyone’s friend, so it never gets in.

    Opening one where it isn’t allowed answers 403 with 50007. A blocked bot can’t message the person who blocked it, as with anyone. Bots never join group DMs, and two bots can’t open a DM with each other.

    A bot’s direct messages always carry their content, even without the MESSAGE_CONTENT intent.

    Looking up users

    GET /users/{user.id} only answers for people the bot shares a server or a DM with, and only with what’s public on their profile. For anyone else it answers 404 with 10013, as if they didn’t exist. That stops a bot from walking through IDs to collect profiles. Within its servers, GET /guilds/{guild.id}/members/{user.id} works as usual.

    Messages

    • Text up to 4,000 characters, twice Discord’s limit for bots. A library that checks the length before sending may still stop at 2,000: JDA does.
    • One sticker per message: a sticker_ids list with more than one is refused.
    • Replies stay in the channel. A message_reference to a message in another channel, or a forward (message_reference.type: 1), is refused with 50035. With fail_if_not_exists: false, a reply to a message that’s gone is sent as a plain message.
    • Files go as in Discord, with multipart/form-data (see Sending files), with the server’s plan limits. A file’s description is kept as its alt text. For now a whole request can’t be bigger than 100 MB, so a file over 100 MB doesn’t get through even when the server’s plan allows it. tts and poll are ignored.
    • Flags. Only SUPPRESS_EMBEDS and IS_COMPONENTS_V2 can be set when sending. On an edit, both can be set but not removed: once a message’s link previews are suppressed, they don’t come back.
    • enforce_nonce remembers a nonce for 5 minutes: sending it again in that time returns the message already created.
    • Mentions. allowed_mentions works as in Discord, and can only take away. Its replied_user is ignored: a reply always notifies the author of the message it answers. Klang has no @here: it’s plain text.
    • Message types. Klang’s role panels, ticket panels and ticket updates arrive as type 0 (default). Pins, members joining, thread notices, AutoMod alerts and poll results use Discord’s types for them.
    • Deleted accounts appear as one user named deleted_user, with ID 1323802873036800000. Webhook messages come with webhook_id and an author with discriminator 0000.
    • People have discriminator 0, and global_name is their display name.
    • Images in embeds go through Klang’s image proxy, as Discord’s go through its own: proxy_url and proxy_icon_url are https://img.klangcdn.com/… addresses. An image on Discord’s servers (cdn.discordapp.com, media.discordapp.net), such as an avatar URL your library built with its default setting, is left out of the embed: Klang never loads images from Discord. Point your library at https://media.klangcdn.com: see Images.

    Moderation

    Bots kick, ban, time out, change nicknames and give roles with the same rules as a person in the app: the permission, being above the other person in the role hierarchy, and never the owner. A few things work differently:

    • A bot never gives a role with a permission it doesn’t have, even a role below its own. In Discord the hierarchy alone decides. This keeps a bot from handing out more than it was given when it was installed. Taking a role away is always fine.
    • Only people in the server can be banned. Banning an ID that isn’t a member answers 404 with 10007.
    • Banning doesn’t delete messages. delete_message_seconds and delete_message_days are checked and then ignored.
    • Bans from the API are permanent until someone lifts them. People in the app can also set a ban to end; the API lists those only while they last.
    • Bans arrive only to bots that can see them. GUILD_BAN_ADD and GUILD_BAN_REMOVE need GUILD_MODERATION and Ban members or View audit log in the server. A logging bot needs the second, not the first.
    • A bulk delete leaves in the app the same trace as deleting each message: a note that a message was there. Bots don’t see it.
    • Voice moderation isn’t available yet: changing a member with mute or deaf set to true, or with any channel_id, answers 50035.

    The reason you send in X-Audit-Log-Reason is kept in the server’s audit log, which bots read with GET /guilds/{guild.id}/audit-logs (see below).

    Managing a server

    Channels, overwrites, roles and invites follow the same rules as a person in the app, with these differences from Discord:

    • Only text, voice and category channels. Other channel types are a 50035, and a channel keeps its type.
    • A bot never touches a bot’s role, its own included: it can’t change or delete one. People who manage the server can.
    • Changing an overwrite asks only for what changes. Like Discord, an overwrite can only allow or deny what the bot has; bits the overwrite already had don’t count again.
    • Ordering roles reads each role’s place, counted from @everyone, as libraries send it. Only the roles that really move need to be below the bot.
    • Roles have one colour and no icon. In colors, only primary_color.
    • Invites can’t be temporary or lead to a stream or an activity. Without max_age they last a day, as in Discord; people in the app make them for a week. A channel’s list needs Manage channels in it.
    • The audit log lists what has a number in Discord. Tickets, role panels, a voice channel’s status, pausing joins and the raid alert, servers made from a template and messages the AutoMod blocked are kept in Klang but not listed. Setting an overwrite is always 14, never 13, and entries from before November 2026 about invites or removed overwrites aren’t listed: they don’t say which. GUILD_AUDIT_LOG_ENTRY_CREATE brings each new entry of those, and only to bots with View audit log in the server.
    • Invites have no events (INVITE_CREATE, INVITE_DELETE) yet.
    • Changes reach the gateway together. Two changes to the same channel or role a moment apart can arrive as one event with the final state.

    Webhooks

    Bots manage a server’s incoming webhooks with the same rules as people in the app (see Webhooks). What differs from Discord:

    • Only in text channels. A voice channel, a category or a thread answers 50035. A webhook can still post in its channel’s threads, with thread_id.
    • Up to 15 per channel and 50 per server. Both answer 30007.
    • Klang’s names. 1 to 80 characters, without “Klang” and other than everyone or here: anything else is a 50035 on name.
    • The avatar is a PNG, JPEG, WebP or GIF image of up to 1 MB, and it can’t be animated. Klang reads the file itself: what the data URI says doesn’t count.
    • Listing a server’s webhooks needs Manage webhooks in the server, and then lists only those of the channels where the bot has it.
    • Webhooks belong to no app. application_id is always null, even for the ones your bot created. user says who created each one.
    • The URL is enough to change one. As in Discord, whoever has a webhook’s URL can rename it, change its avatar or delete it with PATCH and DELETE /webhooks/{webhook.id}/{webhook.token}, without a bot token. discord.js does that by itself when it knows the token, as in webhook.delete(). The audit log then records the change without an author.
    • discord.py’s Webhook.url is built by the library with Discord’s domain. Use the webhook’s id and token, or the url Klang sends, which has Klang’s.

    Threads

    Klang has public threads in text channels: no private threads, no forums and no announcement threads. They arrive as type 11.

    • “Archived” means inactive. A thread with no messages for 7 days shows as archived, with auto_archive_duration 10080. Writing in it brings it back, so there’s no 50083 error.
    • GET /guilds/{guild.id}/channels includes the active threads the bot can see, after the channels.
    • A locked thread refuses messages from anyone who can’t manage threads, with 160005.
    • Nobody archives a thread by hand. archived in PATCH /channels/{thread.id} is accepted and does nothing; the archived list is the inactive threads.
    • Joining a thread is following it, and only the bot itself: adding or removing someone else is a 50013. A thread has no slowmode of its own: it takes its channel’s.
    • member_count is 0 on a thread. THREAD_MEMBERS_UPDATE does count who follows it, up to 50.
    • THREAD_LIST_SYNC only when a channel opens up. It arrives when the bot comes to see a channel that has active threads, after its CHANNEL_CREATE. Not when the bot connects: the active threads already come in each GUILD_CREATE.

    Commands and interactions

    Commands and interactions use Discord’s routes, fields and numbers. What works differently:

    • “Thinking” is only for the person who used the command. After a deferred answer (5), that person sees that the bot is thinking; the rest of the channel sees nothing until the message arrives. Klang doesn’t post a placeholder message, so after a 5 there’s no response_message_id, and @original answers 10008 until the bot sends its message.
    • AutoMod reads the answers. Answers and follow-ups that aren’t ephemeral go through the server’s AutoMod like any bot message. A blocked one answers 400 with 200000, and the bot can try again while its 3 seconds last. Ephemeral ones aren’t read, since only the person sees them.
    • Answers need to see the channel, not Send messages, and slow mode doesn’t apply to them. A bot that can no longer see the channel gets 10003.
    • One connection gets each interaction: the newest connection of the app. Klang runs one shard per bot, so a bot with a second connection open gets them only there.
    • Ephemeral messages aren’t stored. They last the 15 minutes of the interaction, go away when the person reloads the app, don’t notify the people they mention and get no link previews.
    • Only server installs. integration_types is always [0], and the context 2 (group and other private chats) is kept but never used: bots aren’t in those chats in Klang.
    • Attachment options can be registered, but people can’t fill them in yet. The callback and follow-ups take files, in ephemeral messages too: those are deleted an hour after the command was used.
    • Command permissions are set in the app, by role and by channel, by people with Manage server. Bots read them and can’t change them (20001, as in Discord for bot tokens); Klang has no OAuth2 for people yet, so there’s no Bearer token to do it with. Rules for one person can be read but not set. APPLICATION_COMMAND_PERMISSIONS_UPDATE doesn’t arrive yet.
    • Languages. An interaction’s locale is one of the ten locales of Klang’s languages (see Translations), and guild_locale is always en-US. Translations for other locales are kept for your bot, but nobody sees them.
    • default_member_permissions is translated to Klang’s permissions. A bit for something Klang doesn’t have can’t be met, so the command becomes administrators only and reads back as "0".
    • Numbers of exactly ±2⁵³ in an option’s range or choices answer 50035. Use 9007199254740991 (2⁵³ − 1) or less.
    • Paid apps don’t exist: entitlements is always [], and attachment_size_limit is always 25 MB.

    Components and modals

    Buttons, select menus, layout components and modals use Discord’s types, fields, numbers and limits, and the interactions and callbacks work as for commands, with the differences above. What else changes:

    • No buttons that sell. Style 6 (premium, with sku_id) is refused with 50035.
    • Modals have Discord’s fields: labels with a text input, one of the five select menus, a file upload, a radio group, a checkbox group or a checkbox, and text displays, plus the older action rows with a text input.
    • A modal’s files are checked by their bytes, not only by file_types and their extension: a file whose first bytes don’t match its type never reaches your bot. Their size limit is the person’s in that channel, the better of their plan and the server’s, not the attachment_size_limit of the interaction. Their URLs work for a day.
    • discord.py 2.7.1 has no file_types on its FileUpload, so a modal it opens takes any file. discord.js sends it with setFileTypes.
    • Search reads layout components. Klang’s search finds a message with IS_COMPONENTS_V2 by the text of its text displays, and answers to commands by their text, as any message.
    • Incoming webhooks ignore components. Only your app’s webhook, with an interaction’s token, sends them.
    • External images in thumbnails and galleries have to be https addresses on the Internet, and go through Klang’s image proxy. Discord’s image servers are refused instead of loaded.
    • channel_types keeps Discord’s numbers. A channel menu only lists the channels Klang has of those types.
    • A press is checked before your bot gets it: the component has to be on the message as your bot last saved it, enabled, and the values among its options or visible to the person there. What doesn’t fit never reaches your bot. See What Klang checks for you.

    Verification

    Klang verifies bots too, but its own way: a bot can be in 100 servers until Klang’s team verifies it, and then in 2,500. The review counts servers, not users, and covers the app and the privileged intents in one request, made from the developer portal; past 100 servers, an intent that wasn’t reviewed is switched off, and a verified bot asks for the review of its intents alone. Verified bots carry VERIFIED_BOT (1 << 16) in public_flags. See Verify your bot.

    Libraries build message links with Discord’s domain, such as https://discord.com/channels/{guild.id}/{channel.id}/{message.id}. On Klang, replace the domain with app.klang.gg and the link opens in Klang:

    URL
    https://app.klang.gg/channels/{guild.id}/{channel.id}/{message.id}

    @me instead of the server’s ID works too, for direct messages. A bot that reads links in messages should look for app.klang.gg as well.

    What Klang doesn’t have

    These parts of Discord’s API have nothing behind them in Klang. Their routes answer 404, and their events never arrive:

    • announcement channels, forums, media channels, stages and private threads;
    • scheduled events, the soundboard, activities and voice channel effects;
    • text-to-speech messages and @here;
    • app subscriptions, SKUs and entitlements, and apps installed to a user’s account;
    • guild templates, widgets, vanity URLs, welcome screens, onboarding and pruning;
    • ETF encoding and more than one shard per bot.

    Other things exist in Klang but aren’t in the bots’ API yet: voice for bots, presences and typing events. Pins, emojis, reading and editing stickers, polls and their votes, and AutoMod rules arrived in Klang 0.0.27, and creating stickers and managing webhooks in 0.0.28, with a few differences: see Pins, polls, emojis, stickers and AutoMod and Webhooks. The compatibility table lists them one by one.