Struct twilight_util::builder::embed::EmbedBuilder
source · [−]pub struct EmbedBuilder(_);
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
sourceimpl 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".into())
.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. 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();
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
sourceimpl Clone for EmbedBuilder
impl Clone for EmbedBuilder
sourcefn clone(&self) -> EmbedBuilder
fn clone(&self) -> EmbedBuilder
Returns a copy of the value. Read more
1.0.0 · sourcefn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from source
. Read more
sourceimpl Debug for EmbedBuilder
impl Debug for EmbedBuilder
sourceimpl Default for EmbedBuilder
impl Default for EmbedBuilder
sourceimpl From<Embed> for EmbedBuilder
impl From<Embed> for EmbedBuilder
sourceimpl PartialEq<EmbedBuilder> for EmbedBuilder
impl PartialEq<EmbedBuilder> for EmbedBuilder
sourcefn eq(&self, other: &EmbedBuilder) -> bool
fn eq(&self, other: &EmbedBuilder) -> bool
This method tests for self
and other
values to be equal, and is used
by ==
. Read more
sourcefn ne(&self, other: &EmbedBuilder) -> bool
fn ne(&self, other: &EmbedBuilder) -> bool
This method tests for !=
.
sourceimpl TryFrom<EmbedBuilder> for Embed
impl TryFrom<EmbedBuilder> for Embed
sourcefn 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
.
type Error = EmbedValidationError
type Error = EmbedValidationError
The type returned in the event of a conversion error.
impl Eq for EmbedBuilder
impl StructuralEq for EmbedBuilder
impl StructuralPartialEq for EmbedBuilder
Auto Trait Implementations
impl RefUnwindSafe for EmbedBuilder
impl Send for EmbedBuilder
impl Sync for EmbedBuilder
impl Unpin for EmbedBuilder
impl UnwindSafe for EmbedBuilder
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> Instrument for T
impl<T> Instrument for T
sourcefn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
sourcefn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
sourceimpl<T> WithSubscriber for T
impl<T> WithSubscriber for T
sourcefn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> where
S: Into<Dispatch>,
fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> where
S: Into<Dispatch>,
Attaches the provided Subscriber
to this type, returning a
WithDispatch
wrapper. Read more
sourcefn with_current_subscriber(self) -> WithDispatch<Self>
fn with_current_subscriber(self) -> WithDispatch<Self>
Attaches the current default Subscriber
to this type, returning a
WithDispatch
wrapper. Read more