pub struct EmbedBuilder(/* private fields */);
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§
Source§impl EmbedBuilder
impl EmbedBuilder
Sourcepub fn validate(self) -> Result<Self, EmbedValidationError>
pub fn validate(self) -> Result<Self, EmbedValidationError>
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")
.url("https://github.com/twilight-rs/twilight")
.build();
let embed = EmbedBuilder::new().author(author).validate()?.build();
Sourcepub const fn color(self, color: u32) -> Self
pub const fn color(self, color: u32) -> Self
Set the color.
This must be a valid hexadecimal RGB value. 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();
Sourcepub fn description(self, description: impl Into<String>) -> Self
pub fn description(self, description: impl Into<String>) -> Self
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();
Sourcepub fn field(self, field: impl Into<EmbedField>) -> Self
pub fn field(self, field: impl Into<EmbedField>) -> Self
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();
Sourcepub fn image(self, image_source: ImageSource) -> Self
pub fn image(self, image_source: ImageSource) -> Self
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();
Sourcepub fn thumbnail(self, image_source: ImageSource) -> Self
pub fn thumbnail(self, image_source: ImageSource) -> Self
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();
Sourcepub fn title(self, title: impl Into<String>) -> Self
pub fn title(self, title: impl Into<String>) -> Self
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();
Sourcepub fn url(self, url: impl Into<String>) -> Self
pub fn url(self, url: impl Into<String>) -> Self
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§
Source§impl Clone for EmbedBuilder
impl Clone for EmbedBuilder
Source§fn clone(&self) -> EmbedBuilder
fn clone(&self) -> EmbedBuilder
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moreSource§impl Debug for EmbedBuilder
impl Debug for EmbedBuilder
Source§impl Default for EmbedBuilder
impl Default for EmbedBuilder
Source§impl From<Embed> for EmbedBuilder
impl From<Embed> for EmbedBuilder
Source§impl PartialEq for EmbedBuilder
impl PartialEq for EmbedBuilder
Source§impl TryFrom<EmbedBuilder> for Embed
impl TryFrom<EmbedBuilder> for Embed
Source§fn try_from(builder: EmbedBuilder) -> Result<Self, Self::Error>
fn try_from(builder: EmbedBuilder) -> Result<Self, Self::Error>
Convert an embed builder into an embed, validating its contents.
This is equivalent to calling EmbedBuilder::validate
, then
EmbedBuilder::build
.