glyde/payload/message
Bodies for creating and editing a message.
Create and edit are separate types: an empty array is an absence on POST
and an instruction on PATCH. allowed_mentions is required on edit
because an edit without it re-parses the content with Discord’s defaults,
whatever the message was sent with.
Types
POST /channels/{c}/messages/bulk-delete. Two to 100 ids, none older than
14 days, or Discord rejects the whole batch.
pub type BulkDelete {
BulkDelete(messages: List(id.Id(id.Message)))
}
Constructors
-
BulkDelete(messages: List(id.Id(id.Message)))
POST /channels/{c}/messages. Discord needs at least one of content,
embeds, sticker_ids, components, a file or a poll, unless it is a
forward. Not checked here: Discord’s 400 names the bad fields.
pub type CreateMessage {
CreateMessage(
content: option.Option(String),
embeds: List(embed.Embed),
components: List(component.Component),
sticker_ids: List(id.Id(id.Sticker)),
files: List(file.File),
allowed_mentions: option.Option(
allowed_mentions.AllowedMentions,
),
reference: option.Option(Reference),
tts: Bool,
nonce: NoncePolicy,
flags: flags.Flags(message.MessageFlag),
)
}
Constructors
-
CreateMessage( content: option.Option(String), embeds: List(embed.Embed), components: List(component.Component), sticker_ids: List(id.Id(id.Sticker)), files: List(file.File), allowed_mentions: option.Option( allowed_mentions.AllowedMentions, ), reference: option.Option(Reference), tts: Bool, nonce: NoncePolicy, flags: flags.Flags(message.MessageFlag), )Arguments
- content
-
Max 2000 characters.
- embeds
-
Max 10, and 6000 characters across all of them.
- sticker_ids
-
Max 3.
- files
-
Drives both the
attachmentsarray and thefiles[n]parts. - allowed_mentions
-
Noneis Discord’s default: parse and deliver every mention in the content. A decision, not an absence. - nonce
-
Discord ignores
enforce_noncewithout a nonce, so the two are one value and the inert combination cannot be built. - flags
-
Only SUPPRESS_EMBEDS, SUPPRESS_NOTIFICATIONS, IS_VOICE_MESSAGE and IS_COMPONENTS_V2 can be set on a create.
PATCH /channels/{c}/messages/{m}. The attachments array has to name
every attachment that survives the edit, so it and the uploads are one
field.
pub type EditMessage {
EditMessage(
content: field.Field(String),
embeds: field.Field(List(embed.Embed)),
components: field.Field(List(component.Component)),
flags: field.Field(flags.Flags(message.MessageFlag)),
allowed_mentions: allowed_mentions.AllowedMentions,
attachments: file.EditAttachments,
)
}
Constructors
-
EditMessage( content: field.Field(String), embeds: field.Field(List(embed.Embed)), components: field.Field(List(component.Component)), flags: field.Field(flags.Flags(message.MessageFlag)), allowed_mentions: allowed_mentions.AllowedMentions, attachments: file.EditAttachments, )Arguments
- embeds
-
Nullsendsnull.Present([])empties the list, which is what IS_COMPONENTS_V2 requires: it wants[]specifically, notnull. - flags
-
SUPPRESS_EMBEDS can be set and unset. IS_COMPONENTS_V2 can only be set, and never comes off that message again.
- allowed_mentions
-
Not optional. An edit that leaves it out re-parses the content with Discord’s defaults, whatever the message was sent with.
Whether the create carries a nonce, and what Discord should do with it.
pub type NoncePolicy {
NoNonce
UseNonce(value: message.Nonce, enforce: Bool)
}
Constructors
-
NoNonce -
UseNonce(value: message.Nonce, enforce: Bool)Max 25 characters. Always send a
StringNonce.enforcemakes the create idempotent for a few minutes: a second POST with the same nonce returns the first message instead of posting twice.
A reply or a forward, sent as message_reference.
pub type Reference {
Reply(
message_id: id.Id(id.Message),
channel_id: option.Option(id.Id(id.Channel)),
guild_id: option.Option(id.Id(id.Guild)),
fail_if_not_exists: Bool,
)
Forward(
message_id: id.Id(id.Message),
channel_id: id.Id(id.Channel),
guild_id: option.Option(id.Id(id.Guild)),
)
}
Constructors
-
Reply( message_id: id.Id(id.Message), channel_id: option.Option(id.Id(id.Channel)), guild_id: option.Option(id.Id(id.Guild)), fail_if_not_exists: Bool, )Arguments
- channel_id
-
Discord infers the current channel when this is
None. - fail_if_not_exists
-
False turns a reply to a deleted message into a plain message rather than a 400. Discord’s own default is true.
-
Forward( message_id: id.Id(id.Message), channel_id: id.Id(id.Channel), guild_id: option.Option(id.Id(id.Guild)), )Only DEFAULT, REPLY, CHAT_INPUT_COMMAND and CONTEXT_MENU_COMMAND messages can be forwarded, and the app has to be able to read the content or Discord answers error code 160014.
Values
pub fn bulk_delete_body(payload: BulkDelete) -> body.Body
pub fn content(
payload: CreateMessage,
content: String,
) -> CreateMessage
Replaces the text, where embed appends.
pub fn create_body(payload: CreateMessage) -> body.Body
A ready-to-send body, files already paired to their attachments entries.
pub fn edit(
mentions: allowed_mentions.AllowedMentions,
) -> EditMessage
The only constructor: the mention policy is not optional.
pub fn edit_body(payload: EditMessage) -> body.Body
A ready-to-send body for a PATCH, files included.
pub fn edit_entries(
payload: EditMessage,
) -> List(#(String, field.Field(json.Json)))
The edit keys before the absent ones are dropped. Public because the
interaction callback nests the same six keys under data.
pub fn edit_files(payload: EditMessage) -> List(file.File)
The files the multipart body has to carry, in files[n] order.
pub fn embed(
payload: CreateMessage,
embed: embed.Embed,
) -> CreateMessage
Append an embed. Repeated calls build the list up.
pub fn flags_field(
value: flags.Flags(message.MessageFlag),
) -> field.Field(json.Json)
No flags set is an absence, not a zero. Public because a create and an interaction callback both write the key this way.
pub fn forward_of(
message_id: id.Id(id.Message),
from channel_id: id.Id(id.Channel),
) -> CreateMessage
A forward, which carries no content of its own.
pub fn reply_to(
message_id: id.Id(id.Message),
content: String,
) -> CreateMessage
A reply. fail_if_not_exists stays at Discord’s default, so replying to a
message that has since been deleted is a 400.
pub fn text(content: String) -> CreateMessage
pub fn with_correlation_nonce(
payload: CreateMessage,
value: message.Nonce,
) -> CreateMessage
A nonce only for correlating MESSAGE_CREATE back to the create. Discord does not dedupe on it, so a retried POST posts a second message.
pub fn with_nonce(
payload: CreateMessage,
value: message.Nonce,
) -> CreateMessage
A nonce Discord echoes back on MESSAGE_CREATE, enforced, so a retried POST returns the first message rather than posting twice. The safe one is the short name on purpose: a retry is the reason to reach for a nonce at all.