Skip to main content
EmbedBuilder is a builder pattern for creating ApiEmbed. The result is passed to MessagePayload::add_embed or MessagePayload::add_embed_builder.

Limits

FieldMaximum
title256 characters
description4096 characters
fields25 items
field.name256 characters
field.value1024 characters
footer.text2048 characters
author.name256 characters
Total (all text fields combined)6000 characters
build() panics if the total length of all text fields exceeds 6000 characters. All string fields are automatically truncated to their individual limit when set.

Creating

EmbedBuilder::new

pub fn new() -> Self
Creates an empty builder.

EmbedBuilder::from_embed

pub fn from_embed(data: ApiEmbed) -> Self
Creates a builder from an existing ApiEmbed. Use to edit an already-built embed.

Methods

title

pub fn title(self, title: impl Into<String>) -> Self
Sets the embed title. Truncated to 256 characters.

description

pub fn description(self, desc: impl Into<String>) -> Self
Sets the main text of the embed. Supports Markdown. Truncated to 4096 characters.

url

pub fn url(self, url: impl Into<String>) -> Self
Makes the title a clickable link. Not displayed if title is not set.

color

pub fn color(self, color: u32) -> Self
Sets the embed accent color as an RGB integer. Example: 0x5865F2.

color_hex

pub fn color_hex(self, hex: &str) -> Self
Sets the color from a hex string. Accepts "#5865F2" and "5865F2" formats. If the string is invalid, the color is not changed.

color_rgb

pub fn color_rgb(self, r: u8, g: u8, b: u8) -> Self
Sets the color from R, G, B components.

timestamp

pub fn timestamp(self, ts: impl Into<String>) -> Self
Sets a timestamp at the bottom of the embed. Accepts an ISO 8601 string ("2024-01-15T12:00:00Z").
use std::time::{SystemTime, UNIX_EPOCH};

let secs = SystemTime::now()
    .duration_since(UNIX_EPOCH)
    .unwrap()
    .as_secs();

let ts = format!("{secs}");

let embed = EmbedBuilder::new()
    .title("Event")
    .timestamp(ts)
    .build();

author

pub fn author(
    self,
    name: impl Into<String>,
    url: Option<String>,
    icon_url: Option<String>,
) -> Self
Sets the author block at the top of the embed.
ParameterDescription
nameAuthor name. Truncated to 256 characters.
urlLink when clicking the author name.
icon_urlURL of the author icon (displayed to the left of the name).

pub fn footer(self, text: impl Into<String>, icon_url: Option<String>) -> Self
Sets the text and icon at the bottom of the embed. text is truncated to 2048 characters.

image

pub fn image(self, url: impl Into<String>) -> Self
Sets a large image at the bottom of the embed.

thumbnail

pub fn thumbnail(self, url: impl Into<String>) -> Self
Sets a small image in the top-right corner of the embed.

video

pub fn video(self, url: impl Into<String>) -> Self
Sets an embedded video.

audio

pub fn audio(self, url: impl Into<String>) -> Self
Sets embedded audio (Fluxer-specific).

field

pub fn field(
    self,
    name: impl Into<String>,
    value: impl Into<String>,
    inline: bool,
) -> Self
Adds a field to the embed.
ParameterDescription
nameField heading. Truncated to 256 characters.
valueField content. Supports Markdown. Truncated to 1024 characters.
inlineIf true, fields are displayed side by side (up to 3 per row).
Once the 25-field limit is reached, new fields are silently ignored - no panic.

build

pub fn build(self) -> ApiEmbed
Finalizes the builder and returns an ApiEmbed. Panics if the total length of all text fields exceeds 6000 characters.

ApiEmbed

The resulting structure from the fluxer_types crate.
FieldTypeDescription
kindOption<String>Embed type. Always "rich" for bots.
titleOption<String>Title.
descriptionOption<String>Main text.
urlOption<String>Title URL.
colorOption<u32>Accent color (RGB integer).
timestampOption<String>Timestamp (ISO 8601).
authorOption<ApiEmbedAuthor>Author block.
footerOption<ApiEmbedFooter>Footer row.
imageOption<ApiEmbedMedia>Large image.
thumbnailOption<ApiEmbedMedia>Thumbnail.
videoOption<ApiEmbedMedia>Video.
audioOption<ApiEmbedMedia>Audio.
fieldsOption<Vec<ApiEmbedField>>List of fields. None if no fields were added.

Examples

use fluxer_builders::{EmbedBuilder, MessagePayload};

let embed = EmbedBuilder::new()
    .title("Title")
    .color(0x5865F2)
    .build();

let payload = MessagePayload::new().add_embed(embed).build();
channel.send(&rest, &payload).await?;
let embed = EmbedBuilder::new()
    .title("Image of the day")
    .image("https://example.com/image.png")
    .color(0xFEE75C)
    .build();

let payload = MessagePayload::new().add_embed(embed).build();
channel.send(&rest, &payload).await?;
let embed1 = EmbedBuilder::new()
    .title("First block")
    .color(0x5865F2)
    .build();

let embed2 = EmbedBuilder::new()
    .title("Second block")
    .color(0xED4245)
    .build();

let payload = MessagePayload::new()
    .add_embed(embed1)
    .add_embed(embed2)
    .build();

channel.send(&rest, &payload).await?;
let original: ApiEmbed = /* ... */;

let updated = EmbedBuilder::from_embed(original)
    .description("Updated description.")
    .color(0xFEE75C)
    .build();

let payload = MessagePayload::new().add_embed(updated).build();
message.edit(&rest, &payload).await?;