Struct serenity::builder::CreateEmbed[][src]

pub struct CreateEmbed(pub HashMap<&'static str, Value>);
Expand description

A builder to create a fake Embed object, for use with the ChannelId::send_message and ExecuteWebhook::embeds methods.

Examples

Refer to the documentation for ChannelId::send_message for a very in-depth example on how to use this.

Tuple Fields

0: HashMap<&'static str, Value>

Implementations

Build the author of the embed.

Refer to the documentation for CreateEmbedAuthor for more information.

Set the author of the embed.

Set the colour of the left-hand side of the embed.

This is an alias of Self::colour.

Set the colour of the left-hand side of the embed.

Set the description of the embed.

Note: This can’t be longer than 4096 characters.

Set a field. Note that this will not overwrite other fields, and will add to them.

Note: Maximum amount of characters you can put is 256 in a field name and 1024 in a field value.

Adds multiple fields at once.

This is sugar to reduce the need of calling Self::field manually multiple times.

Build the footer of the embed.

Refer to the documentation for CreateEmbedFooter for more information.

Set the footer of the embed.

Set the image associated with the embed. This only supports HTTP(S).

Set the thumbnail of the embed. This only supports HTTP(S).

Set the timestamp.

You may pass a direct string:

  • 2017-01-03T23:00:00
  • 2004-06-08T16:04:23
  • 2004-06-08T16:04:23

This timestamp must be in ISO-8601 format. It must also be in UTC format.

You can also pass an instance of chrono::DateTime<Utc>, which will construct the timestamp string out of it.

Examples

Passing a string timestamp:

use serenity::model::channel::Message;
use serenity::prelude::*;

struct Handler;

#[serenity::async_trait]
impl EventHandler for Handler {
    async fn message(&self, context: Context, mut msg: Message) {
        if msg.content == "~embed" {
            let _ = msg
                .channel_id
                .send_message(&context.http, |m| {
                    m.embed(|e| e.title("hello").timestamp("2004-06-08T16:04:23"));

                    m
                })
                .await;
        }
    }
}

let mut client = Client::builder("token").event_handler(Handler).await?;

client.start().await?;

Creating a join-log:

Note: this example isn’t efficient and is for demonstrative purposes.

use serenity::model::guild::Member;
use serenity::model::id::GuildId;
use serenity::prelude::*;

struct Handler;

#[serenity::async_trait]
impl EventHandler for Handler {
    async fn guild_member_addition(&self, context: Context, guild_id: GuildId, member: Member) {
        if let Ok(guild) = guild_id.to_partial_guild(&context).await {
            let channels = guild.channels(&context).await.unwrap();

            let channel_search = channels.values().find(|c| c.name == "join-log");

            if let Some(channel) = channel_search {
                let user = &member.user;

                let _ = channel
                    .send_message(&context, |m| {
                        m.embed(|e| {
                            e.author(|a| a.icon_url(&user.face()).name(&user.name));
                            e.title("Member Join");

                            if let Some(ref joined_at) = member.joined_at {
                                e.timestamp(joined_at);
                            }

                            e
                        })
                    })
                    .await;
            }
        }
    }
}

let mut client = Client::builder("token").event_handler(Handler).await?;

client.start().await?;

Set the title of the embed.

Set the URL to direct to when clicking on the title.

Same as calling Self::image with “attachment://filename.(jpg, png)”.

Note however, you have to be sure you set an attachment (with ChannelId::send_files) with the provided filename. Or else this won’t work.

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

Creates a builder with default values, setting the type to rich.

Converts the fields of an embed into the values for a new embed builder.

Some values - such as Proxy URLs - are not preserved.

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

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.

Should always be Self

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)

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