pub struct EmbedBuilder(_);
Available on crate feature builder only.
Expand description

Create an Embed with a builder.

Examples

Build a simple embed:

use twilight_util::builder::embed::{EmbedBuilder, EmbedFieldBuilder};

let embed = EmbedBuilder::new()
    .description("Here's a list of reasons why Twilight is the best pony:")
    .field(EmbedFieldBuilder::new("Wings", "She has wings.").inline())
    .field(EmbedFieldBuilder::new("Horn", "She can do magic, and she's really good at it.").inline())
    .validate()?
    .build();

Build an embed with an image:

use twilight_util::builder::embed::{EmbedBuilder, ImageSource};

let embed = EmbedBuilder::new()
    .description("Here's a cool image of Twilight Sparkle")
    .image(ImageSource::attachment("bestpony.png")?)
    .validate()?
    .build();

Implementations

Create a new embed builder.

Build this into an embed.

Ensure the embed is valid.

Errors

Refer to the documentation of twilight_validate::embed::embed for possible errors.

Set the author.

Examples

Create an embed author:

use twilight_util::builder::embed::{EmbedAuthorBuilder, EmbedBuilder};

let author = EmbedAuthorBuilder::new("Twilight".into())
    .url("https://github.com/twilight-rs/twilight")
    .build();

let embed = EmbedBuilder::new().author(author).validate()?.build();

Set the color.

This must be a valid hexadecimal RGB value. 0x000000 is not an acceptable value as it would be thrown out by Discord. Refer to COLOR_MAXIMUM for the maximum acceptable value.

Examples

Set the color of an embed to 0xfd69b3:

use twilight_util::builder::embed::EmbedBuilder;

let embed = EmbedBuilder::new()
    .color(0xfd_69_b3)
    .description("a description")
    .validate()?
    .build();

Set the description.

Refer to DESCRIPTION_LENGTH for the maximum number of UTF-16 code points that can be in a description.

Examples
use twilight_util::builder::embed::EmbedBuilder;

let embed = EmbedBuilder::new()
    .description("this is an embed")
    .validate()?
    .build();

Add a field to the embed.

Examples
use twilight_util::builder::embed::{EmbedBuilder, EmbedFieldBuilder};

let embed = EmbedBuilder::new()
    .description("this is an embed")
    .field(EmbedFieldBuilder::new("a field", "and its value"))
    .validate()?
    .build();

Set the footer of the embed.

Examples
use twilight_util::builder::embed::{EmbedBuilder, EmbedFooterBuilder};

let embed = EmbedBuilder::new()
    .description("this is an embed")
    .footer(EmbedFooterBuilder::new("a footer"))
    .validate()?
    .build();

Set the image.

Examples

Set the image source to a URL:

use twilight_util::builder::embed::{EmbedBuilder, EmbedFooterBuilder, ImageSource};

let source = ImageSource::url("https://raw.githubusercontent.com/twilight-rs/twilight/main/logo.png")?;
let embed = EmbedBuilder::new()
    .footer(EmbedFooterBuilder::new("twilight"))
    .image(source)
    .validate()?
    .build();

Add a thumbnail.

Examples

Set the thumbnail to an image attachment with the filename "twilight.png":

use twilight_util::builder::embed::{EmbedBuilder, ImageSource};

let embed = EmbedBuilder::new()
    .description("a picture of twilight")
    .thumbnail(ImageSource::attachment("twilight.png")?)
    .validate()?
    .build();

Set the ISO 8601 timestamp.

Set the title.

Refer to TITLE_LENGTH for the maximum number of UTF-16 code points that can be in a title.

Examples

Set the title to “twilight”:

use twilight_util::builder::embed::EmbedBuilder;

let embed = EmbedBuilder::new()
    .title("twilight")
    .url("https://github.com/twilight-rs/twilight")
    .validate()?
    .build();

Set the URL.

Examples

Set the URL to twilight’s repository:

use twilight_util::builder::embed::{EmbedBuilder, EmbedFooterBuilder};

let embed = EmbedBuilder::new()
    .description("twilight's repository")
    .url("https://github.com/twilight-rs/twilight")
    .validate()?
    .build();

Trait Implementations

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

Create an embed builder with a default embed.

All embeds have a “rich” type.

Converts to this type from the input type.

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

Convert an embed builder into an embed, validating its contents.

This is equivalent to calling EmbedBuilder::validate, then EmbedBuilder::build.

The type returned in the event of a conversion error.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more

Instruments this type with the current Span, returning an Instrumented wrapper. Read more

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

Uses borrowed data to replace owned data, usually by cloning. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more