pub struct SerenityMessage {
pub content: Option<String>,
pub embeds: Option<Vec<SerenityEmbed>>,
pub tts: bool,
pub mention_type: Option<SerenityMessageMentionType>,
pub sticker_ids: Option<Vec<StickerId>>,
}Expand description
A builder for creating Discord messages using Serenity. This struct allows you to specify various parameters for the message. such as content, embeds, text-to-speech (TTS) settings, mention types, and sticker IDs.
Notes: At the time of the v0.3.0 release, serenity-builder can only generate messages consisting of text strings, embeds, and stickers.
Fields§
§content: Option<String>The content of the message.
Due to Discord API limitations, a maximum of 2000 characters can be used. If the character count exceeds this limit, crate::message::SerenityMessageConvertError::TooLongContent will be returned during conversion.
embeds: Option<Vec<SerenityEmbed>>The embeds to include in the message.
tts: boolWhether the message should be sent as text-to-speech (TTS).
mention_type: Option<SerenityMessageMentionType>The type of mentions to include in the message. For the types of mentions that can be specified, see crate::model::message::SerenityMessageMentionType.
sticker_ids: Option<Vec<StickerId>>The sticker IDs to include in the message.
Implementations§
Source§impl SerenityMessage
impl SerenityMessage
Sourcepub fn convert(&self) -> Result<CreateMessage, SerenityMessageConvertError>
pub fn convert(&self) -> Result<CreateMessage, SerenityMessageConvertError>
Convert the message structure created in Builder into a model usable in Serenity.
let message = SerenityMessage::builder()
.content("This is a test message.")
.build();
let serenity_message = message.convert()?; // Result<CreateMessage, SerenityMessageConvertError>§How to use
// 1. Create a SerenityMessage using the builder
let message = SerenityMessage::builder()
.content("This is a test message.")
.build(); // Don't forget!: If you forget this, you won't be able to use `convert()`.
// 2. Convert to Serenity's CreateMessage
let serenity_message = message.convert()?; // Result<CreateMessage, SerenityMessageConvertError>
// 3. Use the converted message in your bot
if let Err(e) = message.channel_id.send_message(&ctx.http, serenity_message).await {
tracing::error!("Failed to send preview: {:?}", e);
}§Errors
This function may return the following error:
- SerenityMessageConvertError::TooLongContent: The content exceeds the maximum length of 2000 characters.
- SerenityMessageConvertError::EmbedConvertError: Failed to perform internal conversion for embed. (error crate::embed::SerenityEmbedConvertError reported by thiserror)
Source§impl SerenityMessage
impl SerenityMessage
Sourcepub fn builder() -> SerenityMessageBuilder<((), (), (), (), ())>
pub fn builder() -> SerenityMessageBuilder<((), (), (), (), ())>
Create a builder for building SerenityMessage.
On the builder, call .content(...)(optional), .embeds(...)(optional), .tts(...)(optional), .mention_type(...)(optional), .sticker_ids(...)(optional) to set the values of the fields.
Finally, call .build() to create the instance of SerenityMessage.
Trait Implementations§
Source§impl Clone for SerenityMessage
impl Clone for SerenityMessage
Source§fn clone(&self) -> SerenityMessage
fn clone(&self) -> SerenityMessage
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more