Bot API reference
Pins, polls, emojis, stickers and AutoMod
Pinning messages, sending and closing polls, a server's emojis, creating and changing its stickers, and its AutoMod rules. What each route needs, how Klang maps Discord's fields, what it refuses, and the events.
Before you read
Everything on this page goes through the same checks as the app: the same permissions, the
same limits per server tier, and the same audit log. Routes that change something take
X-Audit-Log-Reason, like the moderation routes,
except pins, which Klang doesn’t write to the audit log.
IDs in paths and bodies can be compatible or Klang’s own; answers always carry compatible IDs.
A server the bot isn’t in answers 404 with 10004.
Pins
List the pins
GET /channels/{channel.id}/messages/pinsThe pinned messages, from the most recently pinned. Answers
{ "items": [{ "pinned_at": "…", "message": { … } }], "has_more": false }.
| Query | Type | Notes |
|---|---|---|
before |
ISO 8601 | Only pins made before this moment. Use the last pinned_at of the page you have. |
limit |
1-50 | 50 by default. |
A channel never has more than 50 pins in Klang, so one page always holds them all. The older
GET /channels/{channel.id}/pins works too, and answers the list of messages without the page.
- Needs: to see the channel. Without
MESSAGE_CONTENT, the text comes empty, as in any read. - Rate limit:
bot-read-messages.
Pin and unpin
PUT /channels/{channel.id}/messages/pins/{message.id}
DELETE /channels/{channel.id}/messages/pins/{message.id}Both answer 204, also when the message was already pinned (or wasn’t). Pinning leaves a
message of type 6 in the channel, and everyone who sees it gets a
CHANNEL_PINS_UPDATE. The older
/channels/{channel.id}/pins/{message.id} paths work the same.
- Needs:
PIN_MESSAGESin the channel. In Klang, the olderMANAGE_MESSAGESgives it too. - Rate limit:
message-edit.
| Status | Code | When |
|---|---|---|
400 |
30003 |
The channel already has 50 pins. |
400 |
50021 |
A system message (a pin notice, a poll result…). |
403 |
50013 |
Without the permission. |
404 |
10008 |
The message isn’t in this channel. |
Polls
Send a poll
A poll goes with a message: POST /channels/{channel.id}/messages with poll. Klang reads
Discord’s poll object and checks it with the same rules as a person’s poll:
| Field | Notes |
|---|---|
question.text |
Up to 300 characters, one line. |
answers[].poll_media.text |
From 2 to 10 answers, each up to 55 characters. |
answers[].poll_media.emoji |
A Unicode emoji (name) or a server emoji (id). A server emoji the bot can’t use is dropped. |
duration |
Hours: 1, 4, 8, 24, 72 or 168 (24 by default). Any other number is a 50035. |
allow_multiselect |
false by default. |
layout_type |
Only 1. |
A poll goes on its own: with text, files or a sticker it’s a 50035, and so is a poll in a
message with IS_COMPONENTS_V2. The answer is the message, with its poll.
Who voted
GET /channels/{channel.id}/polls/{message.id}/answers/{answer.id}Answers { "users": [ … ] }, by user ID. after (a user ID) and limit (1-100, 25 by default)
page through them. A message without a poll is a 404 with 10008.
- Needs: to see the channel.
Close a poll
POST /channels/{channel.id}/polls/{message.id}/expireCloses the bot’s own poll now and answers 200 with the message, its results final. The channel
gets the result message (type 46), as when a poll ends on its own. Closing one that already
ended answers the same, without a second result.
| Status | Code | When |
|---|---|---|
403 |
50013 |
The poll isn’t the bot’s. |
404 |
10008 |
There’s no poll in that message. |
Votes as events
With GUILD_MESSAGE_POLLS (or DIRECT_MESSAGE_POLLS in a DM), each vote arrives as
MESSAGE_POLL_VOTE_ADD and each vote
taken back as MESSAGE_POLL_VOTE_REMOVE, one per answer. Changing a vote sends the removal
first. Bots don’t vote.
Emojis
List and read them
GET /guilds/{guild.id}/emojis
GET /guilds/{guild.id}/emojis/{emoji.id}Any bot in the server can read them, as in Discord. Who uploaded each one (user) only goes to
a bot with MANAGE_GUILD_EXPRESSIONS. An emoji of another server is a 404 with 10014.
Klang’s emojis are never limited to roles, never managed, and always need their colons.
Create an emoji
POST /guilds/{guild.id}/emojis| Field | Type | Notes |
|---|---|---|
name |
string | 2 to 32 letters, digits or underscores. Unique in the server, whatever the case. |
image |
image data | data:image/png;base64,… (PNG, JPEG, GIF or WebP), 256 KB at most. Klang reads the file itself: what the data URI says doesn’t count. A GIF, an animated WebP or an APNG is animated. Up to 1024 pixels a side. |
roles |
array | Only empty: an emoji is for everyone in the server. |
Answers 201 with the emoji, and the server’s bots with GUILD_EXPRESSIONS get a
GUILD_EMOJIS_UPDATE.
- Needs:
MANAGE_GUILD_EXPRESSIONS. - Rate limit:
emojis, per server.
| Status | Code | When |
|---|---|---|
400 |
30008 |
The server has as many emojis as its tier allows (25, 50 or 100). |
400 |
50035 |
A name, image or roles that doesn’t fit, or a name already used. |
403 |
50013 |
Without the permission. |
Rename and delete an emoji
PATCH /guilds/{guild.id}/emojis/{emoji.id}
DELETE /guilds/{guild.id}/emojis/{emoji.id}PATCH takes name (and roles, only empty) and answers the emoji; DELETE answers 204.
Messages that used a deleted emoji show its name.
Stickers
List and read them
GET /guilds/{guild.id}/stickers
GET /guilds/{guild.id}/stickers/{sticker.id}Like emojis: any bot in the server, and user only with MANAGE_GUILD_EXPRESSIONS. A Klang
sticker has one emoji, which goes in tags. A sticker of another server is a 404 with
10060.
Create a sticker
POST /guilds/{guild.id}/stickersA multipart/form-data form, as libraries already send it:
| Field | Notes |
|---|---|
name |
2 to 30 characters, not used by another sticker of the server. |
description |
Up to 100 characters. |
tags |
The sticker’s emoji: one Unicode emoji. Anything else, such as an emoji’s name, gives it 🙂. |
file |
The image: PNG (also animated), WebP or GIF, up to 512 KB and 320 × 320 pixels. Klang reads the file’s bytes: a JPEG, a Lottie file or anything else is a 50035. |
const sticker = await guild.stickers.create({
file: './wave.png',
name: 'Harbor wave',
tags: '👋',
description: 'Hello from the harbor',
reason: 'A sticker for greetings',
});sticker = await guild.create_sticker(
name="Harbor wave",
description="Hello from the harbor",
emoji="👋",
file=discord.File("wave.png"),
reason="A sticker for greetings",
)Answers 201 with the sticker, and the server’s bots with GUILD_EXPRESSIONS get a
GUILD_STICKERS_UPDATE:
{
"id": "1575719345115496448",
"name": "Low tide",
"description": "The sea is out",
"tags": "🌊",
"type": 2,
"format_type": 1,
"available": true,
"guild_id": "1575719326438260736",
"user": {
"id": "1575719327113543680",
"username": "lighthouse_8739",
"discriminator": "0",
"global_name": "Lighthouse",
"avatar": null,
"banner": null,
"accent_color": null,
"public_flags": 0,
"bot": true
}
}- Needs:
MANAGE_GUILD_EXPRESSIONS. Klang checks it, the rate limit and the server’s limit before it reads the file. - Rate limit:
stickers, per server. The upload also counts as one of the bot’s two uploads at a time.
| Status | Code | When |
|---|---|---|
400 |
30039 |
The server has as many stickers as its tier allows (5, 15 or 30). |
400 |
50035 |
A field that doesn’t fit, no file, a JSON body, a file that isn’t PNG, WebP or GIF, or a name another sticker of the server has (in errors.name). |
400 |
0 |
An image over 320 × 320 pixels. |
403 |
50013 |
Without the permission. |
413 |
40005 |
A file over 512 KB. Klang stops reading it there. |
Change and delete a sticker
PATCH /guilds/{guild.id}/stickers/{sticker.id}
DELETE /guilds/{guild.id}/stickers/{sticker.id}| Field | Notes |
|---|---|
name |
2 to 30 characters, not used by another sticker of the server (a 50035 on name otherwise). |
description |
Up to 100 characters. "" or null removes it. |
tags |
One emoji, which becomes the sticker’s. Anything else is accepted and leaves the emoji as it was (discord.py sends the emoji’s Unicode name, which Klang can’t turn back into the emoji). |
- Needs:
MANAGE_GUILD_EXPRESSIONS. - Rate limit:
stickers, per server.
AutoMod rules
Klang’s AutoMod works like Discord’s, so most rules map one to one:
| Discord | Klang |
|---|---|
Trigger 1 (keyword): keyword_filter, allow_list |
Words and phrases, with * at the start, the end or both. |
Trigger 5 (mention spam): mention_total_limit |
More than that many mentions in a message (1 to 50). |
Action 1: block the message |
The writer is told which rule stopped it. |
Action 2: an alert in a channel (channel_id) |
A message of type 24 in that channel. |
Action 3: time out (duration_seconds) |
Up to 28 days. |
exempt_roles (20), exempt_channels (50), enabled |
The same. |
What Klang doesn’t have is a 50035 that names the field: the triggers 3 (spam), 4 (preset
word lists) and 6 (member profiles), an event_type other than 1, regex_patterns,
presets, mention_raid_protection_enabled: true (raid protection is a server setting in
Klang), the action 4 (block interactions), a block’s custom_message, and a name over 60
characters.
Klang has two rule types of its own, links and invites to other servers. Bots don’t see them:
they aren’t listed, and reading one is a 404. They count towards the server’s limit of
10 rules.
List and read the rules
GET /guilds/{guild.id}/auto-moderation/rules
GET /guilds/{guild.id}/auto-moderation/rules/{rule.id}- Needs:
MANAGE_GUILD.
Create, change and delete a rule
POST /guilds/{guild.id}/auto-moderation/rules
PATCH /guilds/{guild.id}/auto-moderation/rules/{rule.id}
DELETE /guilds/{guild.id}/auto-moderation/rules/{rule.id}POST needs name, trigger_type and actions, and leaves the rule off unless enabled is
true. PATCH changes what’s sent, field by field (also inside trigger_metadata), and the
trigger can’t change. Both answer 200 with the rule; DELETE answers 204. An alert channel
and the exempt roles and channels must be the server’s.
- Needs:
MANAGE_GUILD. - Rate limit:
automod, per server.
| Status | Code | When |
|---|---|---|
400 |
50035 |
A field Klang doesn’t take, or one that doesn’t fit. |
400 |
0 |
The server already has 10 rules. |
403 |
50013 |
Without MANAGE_GUILD. |
404 |
0 |
No such rule in the server (or one of Klang’s own types). |
Rule events
Bots with MANAGE_GUILD in the server get
AUTO_MODERATION_RULE_CREATE,
_UPDATE and _DELETE with AUTO_MODERATION_CONFIGURATION, whoever changed the rule, and
AUTO_MODERATION_ACTION_EXECUTION with AUTO_MODERATION_EXECUTION: one per action of each rule a
person’s message sets off.