glyde/payload/embed
Building an embed to send.
embed.new()
|> embed.title("glyde")
|> embed.description("A sans-IO Discord library for Gleam.")
|> embed.color(0x5865F2)
|> embed.field("Runs on", "Erlang", inline: True)
Setters replace, field appends. glyde/model/embed is the receive side,
a different type because Discord rejects fields on send that it returns on
receive.
Nothing here checks a length. Discord allows a 256 title, a 4096 description, 25 fields and 6000 characters overall.
Types
Transparent, so a record update works as well as the pipeline.
pub type Embed {
Embed(
title: option.Option(String),
description: option.Option(String),
url: option.Option(String),
timestamp: option.Option(String),
color: option.Option(Int),
footer: option.Option(EmbedFooter),
image: option.Option(String),
thumbnail: option.Option(String),
author: option.Option(EmbedAuthor),
fields: List(EmbedField),
)
}
Constructors
-
Embed( title: option.Option(String), description: option.Option(String), url: option.Option(String), timestamp: option.Option(String), color: option.Option(Int), footer: option.Option(EmbedFooter), image: option.Option(String), thumbnail: option.Option(String), author: option.Option(EmbedAuthor), fields: List(EmbedField), )Arguments
- timestamp
-
ISO-8601. glyde does not own a clock, so this is a string you supply.
- color
-
24-bit RGB, so
0x5865F2is blurple. - image
-
Just the URL: Discord rejects height, width and proxy_url on send. Point it at
attachment://<filename>to use a file uploaded in the same request.
pub type EmbedAuthor {
EmbedAuthor(
name: String,
url: option.Option(String),
icon_url: option.Option(String),
)
}
Constructors
-
EmbedAuthor( name: String, url: option.Option(String), icon_url: option.Option(String), )
pub type EmbedField {
EmbedField(name: String, value: String, inline: Bool)
}
Constructors
-
EmbedField(name: String, value: String, inline: Bool)
pub type EmbedFooter {
EmbedFooter(text: String, icon_url: option.Option(String))
}
Constructors
-
EmbedFooter(text: String, icon_url: option.Option(String))
Values
pub fn character_count(embeds: List(Embed)) -> Int
What Discord counts against total_character_limit: title, description,
footer text, author name, and every field name and value, over all the
embeds a message carries. One embed on its own is character_count([it]).
pub fn field(
embed: Embed,
name: String,
value: String,
inline inline: Bool,
) -> Embed
Append a field. Discord shows up to three inline fields side by side and stacks the rest.
pub fn timestamp(embed: Embed, iso8601: String) -> Embed
ISO-8601, for the timestamp Discord renders in the footer.
pub const total_character_limit: Int
Discord’s cap across every embed on one message, not per embed. In UTF-16 code units, so an emoji spends two of them.