EDA.Embed (EDA v0.3.0)

Copy Markdown View Source

Builder for Discord embed objects.

Provides a pipe-friendly API for constructing embeds with eager validation against Discord's limits.

Example

import EDA.Embed

embed =
  new()
  |> title("My Embed")
  |> description("A cool description")
  |> color(:blurple)
  |> url("https://example.com")
  |> timestamp(DateTime.utc_now())
  |> footer("Footer text", icon_url: "https://example.com/icon.png")
  |> author("Author Name", url: "https://example.com", icon_url: "https://example.com/avatar.png")
  |> thumbnail("https://example.com/thumb.png")
  |> image("https://example.com/image.png")
  |> field("Name", "Value")
  |> field("Inline Field", "Value", inline: true)

EDA.API.Message.create(channel_id, embed: embed)

Summary

Functions

Sets the embed author.

Sets the embed color.

Sets the embed description (max 4096 characters).

Creates a red error embed with the given text as description.

Adds a field to the embed (max 25 fields).

Sets the embed footer.

Sets the embed image URL.

Creates a new empty embed.

Creates a green success embed with the given text as description.

Sets the embed thumbnail URL.

Sets the embed timestamp.

Sets the embed title (max 256 characters).

Converts the embed struct to a plain map, stripping nil values.

Sets the embed URL.

Validates the aggregate 6000-character total limit across all text content.

Like validate/1, but raises on failure.

Types

t()

@type t() :: %EDA.Embed{
  author: map() | nil,
  color: non_neg_integer() | nil,
  description: String.t() | nil,
  fields: [map()],
  footer: map() | nil,
  image: map() | nil,
  thumbnail: map() | nil,
  timestamp: String.t() | nil,
  title: String.t() | nil,
  url: String.t() | nil
}

Functions

author(embed, name, opts \\ [])

@spec author(t(), String.t(), keyword()) :: t()

Sets the embed author.

Options

  • :url - URL of the author
  • :icon_url - URL of author icon

color(embed, value)

@spec color(t(), non_neg_integer() | atom() | String.t()) :: t()

Sets the embed color.

Accepts an integer (0..0xFFFFFF), a color atom (:blurple, :red, etc.), or a hex string ("#FF0000", "#F00", "FF0000").

description(embed, text)

@spec description(t(), String.t()) :: t()

Sets the embed description (max 4096 characters).

error(text)

@spec error(String.t()) :: t()

Creates a red error embed with the given text as description.

Returns a pipeable embed struct — add fields, footer, etc. as needed.

Examples

EDA.Embed.error("Something went wrong")
EDA.Embed.error("Not found") |> EDA.Embed.footer("Try again later")

field(embed, name, value, opts \\ [])

@spec field(t(), String.t(), String.t(), keyword()) :: t()

Adds a field to the embed (max 25 fields).

Options

  • :inline - Whether the field should be inline (default: false)

footer(embed, text, opts \\ [])

@spec footer(t(), String.t(), keyword()) :: t()

Sets the embed footer.

Options

  • :icon_url - URL of footer icon

image(embed, url)

@spec image(t(), String.t()) :: t()

Sets the embed image URL.

new()

@spec new() :: t()

Creates a new empty embed.

success(text)

@spec success(String.t()) :: t()

Creates a green success embed with the given text as description.

Returns a pipeable embed struct — add fields, footer, etc. as needed.

Examples

EDA.Embed.success("User banned successfully")
EDA.Embed.success("Done!") |> EDA.Embed.title("Operation Complete")

thumbnail(embed, url)

@spec thumbnail(t(), String.t()) :: t()

Sets the embed thumbnail URL.

timestamp(embed, dt)

@spec timestamp(t(), DateTime.t() | NaiveDateTime.t() | String.t()) :: t()

Sets the embed timestamp.

Accepts a DateTime, NaiveDateTime, or an ISO 8601 string.

title(embed, text)

@spec title(t(), String.t()) :: t()

Sets the embed title (max 256 characters).

to_map(embed)

@spec to_map(t()) :: map()

Converts the embed struct to a plain map, stripping nil values.

url(embed, url)

@spec url(t(), String.t()) :: t()

Sets the embed URL.

validate(embed)

@spec validate(t()) :: {:ok, t()} | {:error, [String.t()]}

Validates the aggregate 6000-character total limit across all text content.

Returns {:ok, embed} or {:error, reasons}.

validate!(embed)

@spec validate!(t()) :: t()

Like validate/1, but raises on failure.