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

pub struct CreateEmbed(pub Map<String, Value>);

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.

Methods

impl CreateEmbed
[src]

[src]

Set the author of the embed.

Refer to the documentation for CreateEmbedAuthor for more information.

[src]

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

This is an alias of colour.

[src]

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

[src]

Set the description of the embed.

Note: This can't be longer than 2048 characters.

[src]

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

Refer to the documentation for CreateEmbedField for more information.

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

[src]

Adds multiple fields at once.

[src]

Set the footer of the embed.

Refer to the documentation for CreateEmbedFooter for more information.

[src]

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

[src]

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

[src]

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 anything that implements chrono::TimeZone.

Examples

Passing a string timestamp:

struct Handler;
impl EventHandler for Handler {
    fn on_message(&self, _: Context, msg: Message) {
        if msg.content == "~embed" {
            let _ = msg.channel_id.send_message(|m| m
             .embed(|e| e
                    .title("hello")
                    .timestamp("2004-06-08T16:04:23")));
        }
    }
}

let mut client = Client::new("token", Handler); client.start().unwrap();

Creating a join-log:

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

struct Handler;
impl EventHandler for Handler {
    fn on_guild_member_addition(&self, _: Context, guild_id: GuildId, member: Member) {
        use serenity::client::CACHE;
        let cache = CACHE.read().unwrap();

        if let Some(guild) = cache.guild(guild_id) {
            let guild = guild.read().unwrap();

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

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

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

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

                        e
                    }));
            }
        }
    }
}

let mut client = Client::new("token", Handler); client.start().unwrap();

[src]

Set the title of the embed.

[src]

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

[src]

Same as calling [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

impl Clone for CreateEmbed
[src]

[src]

Returns a copy of the value. Read more

1.0.0
[src]

Performs copy-assignment from source. Read more

impl Debug for CreateEmbed
[src]

[src]

Formats the value using the given formatter.

impl Default for CreateEmbed
[src]

[src]

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

impl From<Embed> for CreateEmbed
[src]

[src]

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

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