Struct twilight_embed_builder::EmbedBuilder[][src]

pub struct EmbedBuilder(_);
Expand description

Create an embed with a builder.

Examples

Refer to the crate-level documentation for examples.

Implementations

The maximum number of UTF-16 code points that can be in an author name.

The maximum accepted color value.

The maximum number of UTF-16 code points that can be in a description.

The maximum number of fields that can be in an embed.

The maximum total textual length of the embed in UTF-16 code points.

This combines the text of the author name, description, footer text, field names and values, and title.

The maximum number of UTF-16 code points that can be in a field name.

The maximum number of UTF-16 code points that can be in a field value.

The maximum number of UTF-16 code points that can be in a footer’s text.

The maximum number of UTF-16 code points that can be in a title.

Create a new default embed builder.

See the crate-level documentation for examples and additional information.

This is equivalent to the default implementation.

Build this into an embed.

Errors

Returns an EmbedErrorType::AuthorNameEmpty error type if the provided name is empty.

Returns an EmbedErrorType::AuthorNameTooLong error type if the provided name is longer than AUTHOR_NAME_LENGTH_LIMIT.

Returns an EmbedErrorType::ColorNotRgb error type if the provided color is not a valid RGB integer. Refer to COLOR_MAXIMUM to know what the maximum accepted value is.

Returns an EmbedErrorType::ColorZero error type if the provided color is 0, which is not an acceptable value.

Returns an EmbedErrorType::DescriptionEmpty error type if a provided description is empty.

Returns an EmbedErrorType::DescriptionTooLong error type if a provided description is longer than DESCRIPTION_LENGTH_LIMIT.

Returns an EmbedErrorType::FieldNameEmpty error type if a provided field name is empty.

Returns an EmbedErrorType::FieldNameTooLong error type if a provided field name is longer than FIELD_NAME_LENGTH_LIMIT.

Returns an EmbedErrorType::FieldValueEmpty error type if a provided field value is empty.

Returns an EmbedErrorType::FieldValueTooLong error type if a provided field value is longer than FIELD_VALUE_LENGTH_LIMIT.

Returns an EmbedErrorType::FooterTextEmpty error type if the provided text is empty.

Returns an EmbedErrorType::FooterTextTooLong error type if the provided text is longer than the limit defined at FOOTER_TEXT_LENGTH_LIMIT.

Returns an EmbedErrorType::TitleEmpty error type if the provided title is empty.

Returns an EmbedErrorType::TitleTooLong error type if the provided text is longer than the limit defined at TITLE_LENGTH_LIMIT.

Returns an EmbedErrorType::TooManyFields error type if there are too many fields in the embed. Refer to EMBED_FIELD_LIMIT for the limit value.

Returns an EmbedErrorType::TotalContentTooLarge error type if the textual content of the embed is too large. Refer to EMBED_LENGTH_LIMIT for the limit value and what counts towards it.

Set the author.

Examples

Create an embed author:

use twilight_embed_builder::{EmbedAuthorBuilder, EmbedBuilder};

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

let embed = EmbedBuilder::new().author(author).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_embed_builder::EmbedBuilder;

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

Set the description.

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

Examples

use twilight_embed_builder::EmbedBuilder;

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

Add a field to the embed.

Examples

use twilight_embed_builder::{EmbedBuilder, EmbedFieldBuilder};

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

Set the footer of the embed.

Examples

use twilight_embed_builder::{EmbedBuilder, EmbedFooterBuilder};

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

Set the image.

Examples

Set the image source to a URL:

use twilight_embed_builder::{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)
    .build()?;

Add a thumbnail.

Examples

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

use twilight_embed_builder::{EmbedBuilder, ImageSource};

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

Set the ISO 8601 timestamp.

Set the title.

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

Examples

Set the title to “twilight”:

use twilight_embed_builder::EmbedBuilder;

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

Set the URL.

Examples

Set the URL to twilight’s repository:

use twilight_embed_builder::{EmbedBuilder, EmbedFooterBuilder};

let embed = EmbedBuilder::new()
    .description("twilight's repository")
    .url("https://github.com/twilight-rs/twilight")
    .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.

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.

This is equivalent to calling 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

Performs the conversion.

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

Performs the conversion.

The resulting type after obtaining ownership.

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

🔬 This is a nightly-only experimental API. (toowned_clone_into)

recently added

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.