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
.
impl Eq for EmbedBuilder
impl StructuralPartialEq for EmbedBuilder
Auto Trait Implementations§
impl Freeze for EmbedBuilder
impl RefUnwindSafe for EmbedBuilder
impl Send for EmbedBuilder
impl Sync for EmbedBuilder
impl Unpin for EmbedBuilder
impl UnwindSafe for EmbedBuilder
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)