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

pub type EmbedAuthor {
  EmbedAuthor(
    name: String,
    url: option.Option(String),
    icon_url: option.Option(String),
  )
}

Constructors

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

Values

pub fn author(embed: Embed, name: String) -> Embed
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 color(embed: Embed, rgb: Int) -> Embed

The colour of the bar down the left, as 24-bit RGB.

pub fn description(embed: Embed, description: String) -> Embed
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 footer(embed: Embed, text: String) -> Embed
pub fn image(embed: Embed, url: String) -> Embed
pub fn new() -> Embed
pub fn thumbnail(embed: Embed, url: String) -> Embed
pub fn timestamp(embed: Embed, iso8601: String) -> Embed

ISO-8601, for the timestamp Discord renders in the footer.

pub fn title(embed: Embed, title: String) -> Embed
pub fn to_json(embed: Embed) -> json.Json

Public so a hand-rolled request can reuse it.

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.

pub fn url(embed: Embed, url: String) -> Embed

Makes the title a link. Without a title it shows nothing.

Search Document