glyde/embed

Message embeds. One type for both directions: the receive-only fields (type, provider, video, proxy urls, media sizes) are None on a value you build and to_json never writes them, so a received embed round-trips through a draft without a conversion.

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. Nothing checks a length. Discord allows a 256 title, a 4096 description, 25 fields and 6000 characters overall.

Types

pub type Embed {
  Embed(
    title: option.Option(String),
    type_: option.Option(EmbedType),
    description: option.Option(String),
    url: option.Option(String),
    timestamp: option.Option(String),
    color: option.Option(Int),
    footer: option.Option(EmbedFooter),
    image: option.Option(EmbedMedia),
    thumbnail: option.Option(EmbedMedia),
    video: option.Option(EmbedMedia),
    provider: option.Option(EmbedProvider),
    author: option.Option(EmbedAuthor),
    fields: List(EmbedField),
    flags: flags.Flags(EmbedFlag),
  )
}

Constructors

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

Constructors

pub type EmbedField {
  EmbedField(name: String, value: String, inline: Bool)
}

Constructors

  • EmbedField(name: String, value: String, inline: Bool)

    name max 256, value max 1024, and 6000 characters across the embed.

pub type EmbedFlag {
  IsContentInventoryEntry
}

Constructors

  • IsContentInventoryEntry

    The embed is a content inventory entry, which a bot never sends.

pub type EmbedFooter {
  EmbedFooter(
    text: String,
    icon_url: option.Option(String),
    proxy_icon_url: option.Option(String),
  )
}

Constructors

  • EmbedFooter(
      text: String,
      icon_url: option.Option(String),
      proxy_icon_url: option.Option(String),
    )

    Arguments

    text

    Max 2048 characters.

    proxy_icon_url

    Receive only.

One record for image, thumbnail and video. On send only url goes out; Discord rejects height, width and proxy_url on an embed you post.

pub type EmbedMedia {
  EmbedMedia(
    url: option.Option(String),
    proxy_url: option.Option(String),
    dimensions: option.Option(attachment.Dimensions),
    content_type: option.Option(String),
    placeholder: option.Option(attachment.Placeholder),
    description: option.Option(String),
    flags: flags.Flags(EmbedMediaFlag),
  )
}

Constructors

pub type EmbedMediaFlag {
  IsAnimated
}

Constructors

  • IsAnimated

Its own type, not the attachment one: Discord documents a separate table for embed media, and today it names a single bit.

pub type EmbedMediaFlags =
  flags.Flags(EmbedMediaFlag)
pub type EmbedProvider {
  EmbedProvider(
    name: option.Option(String),
    url: option.Option(String),
  )
}

Constructors

Discord’s documented embed types. Only Rich is ever sent by a bot; the rest are what the client made of a link. An open set on the wire, so a value this build has no name for decodes as None.

pub type EmbedType {
  Rich
  Image
  Video
  Gifv
  Article
  Link
  PollResult
  AutoModerationMessage
}

Constructors

  • Rich
  • Image
  • Video
  • Gifv
  • Article
  • Link
  • PollResult
  • AutoModerationMessage

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 decoder() -> decode.Decoder(Embed)
pub fn description(embed: Embed, description: String) -> Embed
pub fn embed_type_from_string(
  value: String,
) -> option.Option(EmbedType)
pub fn embed_type_to_string(value: EmbedType) -> String
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 has_flag(
  bits: flags.Flags(EmbedFlag),
  flag: EmbedFlag,
) -> Bool
pub fn has_media_flag(
  bits: flags.Flags(EmbedMediaFlag),
  flag: EmbedMediaFlag,
) -> Bool
pub fn image(embed: Embed, url: String) -> Embed
pub fn new() -> Embed

An empty embed, to pipe setters onto.

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

The send shape. Type, provider, video, proxy urls and media sizes are not written: Discord ignores them on a create anyway.

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