glyde/api/channel
Messages, reactions, pins, typing, the channel itself, and the threads that hang off one.
let call = channel.create_message(channel_id, body.json(fields))
let request = rest.request(config, call)
Types
Where in a channel’s history to read. One value, not three optional fields, because Discord rejects two cursors on one request.
pub type MessageCursor {
Around(id.Id(id.Message))
Before(id.Id(id.Message))
After(id.Id(id.Message))
}
Constructors
-
Around(id.Id(id.Message))Centred on a message, returning the ones either side of it.
-
Before(id.Id(id.Message))Older than a message.
-
After(id.Id(id.Message))Newer than a message.
The {emoji} in a reaction path. Only ever decoded text, so a value that
is already percent-encoded cannot be handed in and encoded twice.
pub opaque type ReactionEmoji
Which reactions the route asks for. Two variants and not the model’s
ReactionType: that one has an unknown tail for reading events, and
putting a number Discord does not know on type is a 400.
pub type ReactionKind {
Normal
Burst
}
Constructors
-
Normal -
Burst
A point in time to page back from. Three routes here order by an instant
instead of by snowflake, and a snowflake in one of their before
parameters is accepted and answers the wrong window, so this is not a
MessageCursor and not a bare string.
pub opaque type TimeCursor
A reaction type this route cannot ask for: a kind Discord added after this
build. wire_value is the number it sent, which is a value to handle and
not one to put on a query string.
pub type UnsendableReaction {
UnsendableReaction(wire_value: Int)
}
Constructors
-
UnsendableReaction(wire_value: Int)
Values
pub fn add_thread_member(
thread: id.Id(id.Channel),
user: id.Id(id.User),
) -> rest.Call(Nil)
PUT /channels/{thread.id}/thread-members/{user.id}.
pub fn archived_at(thread: channel.ThreadMetadata) -> TimeCursor
When a thread was archived, which is the order the archived listings come in. Page on with the oldest thread you just read.
pub fn at_time(iso8601: String) -> TimeCursor
An instant of your own, as ISO-8601. Every timestamp Discord sends is already in this shape.
pub fn bulk_delete_messages(
channel: id.Id(id.Channel),
body: body.Body,
) -> rest.Call(Nil)
POST /channels/{channel.id}/messages/bulk-delete. Discord takes 2 to 100
ids and rejects the whole request if any message is over two weeks old.
pub fn create_message(
channel: id.Id(id.Channel),
body: body.Body,
) -> rest.Call(message.Message)
POST /channels/{channel.id}/messages. Attach files with rest.attach.
pub fn create_reaction(
channel: id.Id(id.Channel),
message: id.Id(id.Message),
emoji: ReactionEmoji,
) -> rest.Call(Nil)
PUT /channels/{channel.id}/messages/{message.id}/reactions/{emoji}/@me.
pub fn custom_emoji(
emoji: id.Id(id.Emoji),
name: String,
) -> ReactionEmoji
A custom guild emoji, which Discord wants as name:id. The colon is
percent-encoded on the way out, which Discord accepts.
pub fn custom_emoji_by_id(
emoji: id.Id(id.Emoji),
) -> ReactionEmoji
A custom emoji whose name you do not have. Discord reads only the id, so
the name goes out as the literal e.
pub fn delete_all_reactions(
channel: id.Id(id.Channel),
message: id.Id(id.Message),
) -> rest.Call(Nil)
DELETE /channels/{channel.id}/messages/{message.id}/reactions, every
reaction on the message. Its own bucket, having no emoji to collapse at.
pub fn delete_channel(
channel: id.Id(id.Channel),
) -> rest.Call(channel.Channel)
DELETE /channels/{channel.id}, which closes a DM and deletes anything
else. Answers with the channel it removed, not 204.
pub fn delete_channel_permission(
channel: id.Id(id.Channel),
overwrite: id.Id(id.Overwrite),
) -> rest.Call(Nil)
pub fn delete_emoji_reactions(
channel: id.Id(id.Channel),
message: id.Id(id.Message),
emoji: ReactionEmoji,
) -> rest.Call(Nil)
DELETE /channels/{channel.id}/messages/{message.id}/reactions/{emoji},
every user’s reaction with that one emoji.
pub fn delete_message(
channel: id.Id(id.Channel),
message: id.Id(id.Message),
) -> rest.Call(Nil)
DELETE /channels/{channel.id}/messages/{message.id}. Discord splits this
route into three buckets by the target’s age and reports none of it in the
headers (discord-api-docs#1092, #1295), so route.Aged carries the age.
pub fn delete_own_reaction(
channel: id.Id(id.Channel),
message: id.Id(id.Message),
emoji: ReactionEmoji,
) -> rest.Call(Nil)
DELETE /channels/{channel.id}/messages/{message.id}/reactions/{emoji}/@me.
pub fn delete_user_reaction(
channel: id.Id(id.Channel),
message: id.Id(id.Message),
emoji: ReactionEmoji,
user: id.Id(id.User),
) -> rest.Call(Nil)
DELETE /channels/{channel.id}/messages/{message.id}/reactions/{emoji}/{user.id}.
pub fn edit_channel(
channel: id.Id(id.Channel),
body: body.Body,
name_or_topic name_or_topic: Bool,
) -> rest.Call(channel.Channel)
PATCH /channels/{channel.id}. Name and topic edits carry an undocumented
limit of two per ten minutes, and glyde cannot see inside the body, so
name_or_topic puts the call in that sublimit rather than letting it spend
the channel’s whole PATCH budget. payload/channel.edits_name_or_topic is
the answer for an EditGuildChannel.
pub fn edit_channel_permissions(
channel: id.Id(id.Channel),
overwrite: id.Id(id.Overwrite),
body: body.Body,
) -> rest.Call(Nil)
PUT /channels/{channel.id}/permissions/{overwrite.id}. The overwrite id
is a role id or a user id, and only the type in the body says which.
pub fn edit_message(
channel: id.Id(id.Channel),
message: id.Id(id.Message),
body: body.Body,
) -> rest.Call(message.Message)
PATCH /channels/{channel.id}/messages/{message.id}. An attachments
array is the complete list of files to keep, so anything left out is
deleted. Omitting the key keeps them all.
pub fn get_channel(
channel: id.Id(id.Channel),
) -> rest.Call(channel.Channel)
pub fn get_message(
channel: id.Id(id.Channel),
message: id.Id(id.Message),
) -> rest.Call(message.Message)
pub fn get_messages(
channel: id.Id(id.Channel),
cursor cursor: option.Option(MessageCursor),
limit limit: option.Option(Int),
) -> rest.Call(List(message.Message))
GET /channels/{channel.id}/messages. None is no cursor, which Discord
reads as the newest messages. Discord caps limit at 100 and defaults it
to 50.
pub fn get_pins(
channel: id.Id(id.Channel),
before before: option.Option(TimeCursor),
limit limit: option.Option(Int),
) -> rest.Call(message.PinList)
GET /channels/{channel.id}/messages/pins, each message wrapped in its pin
time. Pages backwards through the order the messages were pinned in.
pub fn get_private_archived_threads(
channel: id.Id(id.Channel),
before before: option.Option(TimeCursor),
limit limit: option.Option(Int),
) -> rest.Call(channel.ThreadList)
GET /channels/{channel.id}/threads/archived/private, which needs
MANAGE_THREADS.
pub fn get_public_archived_threads(
channel: id.Id(id.Channel),
before before: option.Option(TimeCursor),
limit limit: option.Option(Int),
) -> rest.Call(channel.ThreadList)
GET /channels/{channel.id}/threads/archived/public, newest archive first.
pub fn get_reactions(
channel: id.Id(id.Channel),
message: id.Id(id.Message),
emoji: ReactionEmoji,
type_ type_: option.Option(ReactionKind),
after after: option.Option(id.Id(id.User)),
limit limit: option.Option(Int),
) -> rest.Call(List(user.User))
GET /channels/{channel.id}/messages/{message.id}/reactions/{emoji}, the
users who reacted with it.
pub fn join_thread(thread: id.Id(id.Channel)) -> rest.Call(Nil)
PUT /channels/{thread.id}/thread-members/@me.
pub fn leave_thread(thread: id.Id(id.Channel)) -> rest.Call(Nil)
DELETE /channels/{thread.id}/thread-members/@me.
pub fn pin_message(
channel: id.Id(id.Channel),
message: id.Id(id.Message),
) -> rest.Call(Nil)
PUT /channels/{channel.id}/messages/pins/{message.id}.
pub fn pinned_at(pin: message.PinnedMessage) -> TimeCursor
When a message was pinned. Page on with the oldest entry you just read.
pub fn reaction_emoji(emoji: emoji.Emoji) -> ReactionEmoji
An emoji that came off the wire, from a reaction event or a component.
pub fn reaction_kind(
value: message.ReactionType,
) -> Result(ReactionKind, UnsendableReaction)
Narrow a reaction type read off a MESSAGE_REACTION_ADD into one this route can ask for.
pub fn remove_thread_member(
thread: id.Id(id.Channel),
user: id.Id(id.User),
) -> rest.Call(Nil)
DELETE /channels/{thread.id}/thread-members/{user.id}.
pub fn start_thread(
channel: id.Id(id.Channel),
body: body.Body,
) -> rest.Call(channel.Channel)
POST /channels/{channel.id}/threads, a thread with no starter message.
The same path creates a forum or media post, with a different body.
pub fn start_thread_from_message(
channel: id.Id(id.Channel),
message: id.Id(id.Message),
body: body.Body,
) -> rest.Call(channel.Channel)
POST /channels/{channel.id}/messages/{message.id}/threads, a thread
hanging off an existing message.
pub fn trigger_typing(
channel: id.Id(id.Channel),
) -> rest.Call(Nil)
POST /channels/{channel.id}/typing. The indicator lasts ten seconds or
until the bot posts.
pub fn unicode_emoji(text: String) -> ReactionEmoji
A standard emoji, written as the characters themselves: "🔥".
pub fn unpin_message(
channel: id.Id(id.Channel),
message: id.Id(id.Message),
) -> rest.Call(Nil)
DELETE /channels/{channel.id}/messages/pins/{message.id}.