serenity_builder/model/
embed.rs

1/// A builder for creating Discord embeds.
2/// This struct allows you to build rich embed messages for Discord using a fluent interface.
3///
4/// Fundamentally, this structure provides the same functionality as Serenity, but this library explicitly removes values that became unnecessary during optimization as a builder.
5///
6/// # Structure Values
7///
8/// In Serenity, embeddings are composed of multiple structures such as [serenity::builder::CreateEmbedAuthor].
9///
10/// serenity-builder represents these structures as Triples or Doubles. Please refer to the documentation to determine which values correspond to them.
11///
12/// [What is Triples or Doubles?](https://doc.rust-lang.org/book/ch03-02-data-types.html)
13///
14/// # Values
15///
16/// The following values have been removed from [serenity::model::channel::Embed]:
17///
18/// - `kind`: The type of embed. Discord currently only supports "rich" embeds, so this field is unnecessary.
19/// - `video`: `rich` embeds do not support video content, so this field is unnecessary.
20/// - `provider`: `rich` embeds do not support provider information, so this field is unnecessary.
21#[derive(serde::Deserialize, typed_builder::TypedBuilder, Clone)]
22pub struct SerenityEmbed {
23    /// The title of the embed.
24    #[builder(default, setter(strip_option, into))]
25    pub title: Option<String>,
26    /**
27     * The description of the embed.
28     *
29     * Due to Discord API limitations, a maximum of 4096 characters can be used. If the character count exceeds this limit, [crate::embed::SerenityEmbedConvertError::TooLongDescription] will be returned during conversion.
30     */
31    #[builder(default, setter(strip_option, into))]
32    pub description: Option<String>,
33    // The url of the embed.
34    #[builder(default, setter(strip_option, into))]
35    pub url: Option<String>,
36    /**
37     * The timestamp of the embed content.
38     * It will be displayed at the bottom of the embed.
39     */
40    #[builder(default, setter(strip_option, into))]
41    pub timestamp: Option<serenity::all::Timestamp>,
42    /**
43     * The color of the embed.
44     *
45     * Serenity uses [serenity::model::colour::Colour], but Builder only allows direct specification from color codes.
46     * e.g. `0xff0000` for red.
47     */
48    #[builder(default, setter(strip_option, into))]
49    pub color: Option<u32>,
50    /// The footer of the embed.
51    #[builder(default, setter(strip_option, into))]
52    pub footer_text: Option<String>,
53    /// The footer icon url of the embed.
54    #[builder(default, setter(strip_option, into))]
55    pub footer_icon_url: Option<String>,
56    /// The image url of the embed.
57    #[builder(default, setter(strip_option, into))]
58    pub image_url: Option<String>,
59    /// The thumbnail url of the embed.
60    #[builder(default, setter(strip_option, into))]
61    pub thumbnail_url: Option<String>,
62    /// The author name of the embed.
63    #[builder(default, setter(strip_option, into))]
64    pub author_name: Option<String>,
65    /// The author url of the embed.
66    #[builder(default, setter(strip_option, into))]
67    pub author_url: Option<String>,
68    /// The author icon url of the embed.
69    #[builder(default, setter(strip_option, into))]
70    pub author_icon_url: Option<String>,
71    /**
72     * The fields of the embed. (up to 25 fields)
73     *
74     * Due to Discord API limitations, only 25 fields can be used. Any additional fields will result in a [crate::embed::SerenityEmbedConvertError::TooManyFields] being returned during conversion.
75     */
76    #[builder(default, setter(strip_option, into))]
77    pub fields: Option<Vec<SerenityEmbedField>>,
78}
79
80/// Field structures used in [SerenityEmbed].
81/// These structures can be used as Vec (arrays) in [SerenityEmbed] and are internally converted to be handled by [serenity::model::channel::Embed].
82#[derive(serde::Deserialize, typed_builder::TypedBuilder, Clone)]
83pub struct SerenityEmbedField {
84    /// The name of the field.
85    #[builder(setter(into))]
86    pub name: String,
87    /// The value of the field.
88    #[builder(setter(into))]
89    pub value: String,
90    /// Whether the field is displayed inline. (default: false)
91    #[builder(default = false, setter(into))]
92    pub inline: bool,
93}