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

pub struct CreateEmbed(pub HashMap<&'static str, 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]

pub fn author<F>(&mut self, f: F) -> &mut Self where
    F: FnOnce(&mut CreateEmbedAuthor) -> &mut CreateEmbedAuthor
[src]

Set the author of the embed.

Refer to the documentation for CreateEmbedAuthor for more information.

pub fn color<C: Into<Colour>>(&mut self, colour: C) -> &mut Self[src]

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

This is an alias of colour.

pub fn colour<C: Into<Colour>>(&mut self, colour: C) -> &mut Self[src]

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

pub fn description<D: ToString>(&mut self, description: D) -> &mut Self[src]

Set the description of the embed.

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

pub fn field<T, U>(&mut self, name: T, value: U, inline: bool) -> &mut Self where
    T: ToString,
    U: ToString
[src]

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.

pub fn fields<T, U, It>(&mut self, fields: It) -> &mut Self where
    It: IntoIterator<Item = (T, U, bool)>,
    T: ToString,
    U: ToString
[src]

Adds multiple fields at once.

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

pub fn footer<F>(&mut self, f: F) -> &mut Self where
    F: FnOnce(&mut CreateEmbedFooter) -> &mut CreateEmbedFooter
[src]

Set the footer of the embed.

Refer to the documentation for CreateEmbedFooter for more information.

pub fn image<S: ToString>(&mut self, url: S) -> &mut Self[src]

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

pub fn thumbnail<S: ToString>(&mut self, url: S) -> &mut Self[src]

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

pub fn timestamp<T: Into<Timestamp>>(&mut self, timestamp: T) -> &mut Self[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 an instance of chrono::DateTime<Utc>, which will construct the timestamp string out of it.

Examples

Passing a string timestamp:

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

struct Handler;

impl EventHandler for Handler {
    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
            });
        }
    }
}

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

client.start().unwrap();

Creating a join-log:

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

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

struct Handler;

impl EventHandler for Handler {
    fn guild_member_addition(&self, context: Context, guild_id: GuildId, member: Member) {
        let cache = context.cache.read();

        if let Ok(guild) = guild_id.to_partial_guild(&context) {
            let channels = guild.channels(&context)
                .unwrap();

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

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

                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
                    })
                });
            }
        }
    }
}

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

client.start().unwrap();

pub fn title<D: ToString>(&mut self, title: D) -> &mut Self[src]

Set the title of the embed.

pub fn url<S: ToString>(&mut self, url: S) -> &mut Self[src]

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

pub fn attachment<S: ToString>(&mut self, filename: S) -> &mut Self[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]

impl Debug for CreateEmbed[src]

impl Default for CreateEmbed[src]

fn default() -> CreateEmbed[src]

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

impl From<Embed> for CreateEmbed[src]

fn from(embed: Embed) -> Self[src]

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

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> CloneAny for T where
    T: Clone + Any
[src]

impl<T> DebugAny for T where
    T: Any + Debug
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> Same<T> for T

type Output = T

Should always be Self

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<T> UnsafeAny for T where
    T: Any

impl<V, T> VZip<V> for T where
    V: MultiLane<T>,