Struct serenity::builder::CreateMessage
source · [−]pub struct CreateMessage<'a>(pub HashMap<&'static str, Value>, pub Option<Vec<ReactionType>>, pub Vec<AttachmentType<'a>>);
builder
only.Expand description
A builder to specify the contents of an Http::send_message
request,
primarily meant for use through ChannelId::send_message
.
There are three situations where different field requirements are present:
- When sending a message without embeds or stickers,
Self::content
is the only required field that is required to be set. - When sending an
Self::embed
, no other field is required. - When sending stickers with
Self::sticker_id
or other sticker methods, no other field is required.
Note that if you only need to send the content of a message, without
specifying other fields, then ChannelId::say
may be a more preferable
option.
Examples
Sending a message with a content of "test"
and applying text-to-speech:
use serenity::model::id::ChannelId;
let channel_id = ChannelId(7);
let _ = channel_id.send_message(&http, |m| {
m.content("test")
.tts(true)
.embed(|e| e.title("This is an embed").description("With a description"))
});
Tuple Fields
0: HashMap<&'static str, Value>
1: Option<Vec<ReactionType>>
2: Vec<AttachmentType<'a>>
model
only.Implementations
sourceimpl<'a> CreateMessage<'a>
impl<'a> CreateMessage<'a>
sourcepub fn content<D: ToString>(&mut self, content: D) -> &mut Self
pub fn content<D: ToString>(&mut self, content: D) -> &mut Self
Set the content of the message.
Note: Message contents must be under 2000 unicode code points.
sourcepub fn add_embed<F>(&mut self, f: F) -> &mut Self where
F: FnOnce(&mut CreateEmbed) -> &mut CreateEmbed,
pub fn add_embed<F>(&mut self, f: F) -> &mut Self where
F: FnOnce(&mut CreateEmbed) -> &mut CreateEmbed,
Add an embed for the message.
Note: This will keep all existing embeds. Use Self::set_embed()
to replace existing
embeds.
sourcepub fn add_embeds(&mut self, embeds: Vec<CreateEmbed>) -> &mut Self
pub fn add_embeds(&mut self, embeds: Vec<CreateEmbed>) -> &mut Self
Add multiple embeds for the message.
Note: This will keep all existing embeds. Use Self::set_embeds()
to replace existing
embeds.
sourcepub fn embed<F>(&mut self, f: F) -> &mut Self where
F: FnOnce(&mut CreateEmbed) -> &mut CreateEmbed,
pub fn embed<F>(&mut self, f: F) -> &mut Self where
F: FnOnce(&mut CreateEmbed) -> &mut CreateEmbed,
Set an embed for the message.
Equivalent to Self::set_embed()
.
Note: This will replace all existing embeds. Use
Self::add_embed()
to add an additional embed.
sourcepub fn set_embed(&mut self, embed: CreateEmbed) -> &mut Self
pub fn set_embed(&mut self, embed: CreateEmbed) -> &mut Self
Set an embed for the message.
Equivalent to Self::embed()
.
Note: This will replace all existing embeds.
Use Self::add_embed()
to add an additional embed.
sourcepub fn set_embeds(&mut self, embeds: Vec<CreateEmbed>) -> &mut Self
pub fn set_embeds(&mut self, embeds: Vec<CreateEmbed>) -> &mut Self
Set multiple embeds for the message.
Note: This will replace all existing embeds. Use Self::add_embeds()
to keep existing
embeds.
sourcepub fn tts(&mut self, tts: bool) -> &mut Self
pub fn tts(&mut self, tts: bool) -> &mut Self
Set whether the message is text-to-speech.
Think carefully before setting this to true
.
Defaults to false
.
sourcepub fn reactions<R: Into<ReactionType>, It: IntoIterator<Item = R>>(
&mut self,
reactions: It
) -> &mut Self
pub fn reactions<R: Into<ReactionType>, It: IntoIterator<Item = R>>(
&mut self,
reactions: It
) -> &mut Self
Adds a list of reactions to create after the message’s sent.
sourcepub fn add_file<T: Into<AttachmentType<'a>>>(&mut self, file: T) -> &mut Self
Available on crate feature model
only.
pub fn add_file<T: Into<AttachmentType<'a>>>(&mut self, file: T) -> &mut Self
model
only.Appends a file to the message.
sourcepub fn add_files<T: Into<AttachmentType<'a>>, It: IntoIterator<Item = T>>(
&mut self,
files: It
) -> &mut Self
Available on crate feature model
only.
pub fn add_files<T: Into<AttachmentType<'a>>, It: IntoIterator<Item = T>>(
&mut self,
files: It
) -> &mut Self
model
only.Appends a list of files to the message.
sourcepub fn files<T: Into<AttachmentType<'a>>, It: IntoIterator<Item = T>>(
&mut self,
files: It
) -> &mut Self
Available on crate feature model
only.
pub fn files<T: Into<AttachmentType<'a>>, It: IntoIterator<Item = T>>(
&mut self,
files: It
) -> &mut Self
model
only.Sets a list of files to include in the message.
Calling this multiple times will overwrite the file list.
To append files, call Self::add_file
or Self::add_files
instead.
sourcepub fn allowed_mentions<F>(&mut self, f: F) -> &mut Self where
F: FnOnce(&mut CreateAllowedMentions) -> &mut CreateAllowedMentions,
pub fn allowed_mentions<F>(&mut self, f: F) -> &mut Self where
F: FnOnce(&mut CreateAllowedMentions) -> &mut CreateAllowedMentions,
Set the allowed mentions for the message.
sourcepub fn reference_message(
&mut self,
reference: impl Into<MessageReference>
) -> &mut Self
pub fn reference_message(
&mut self,
reference: impl Into<MessageReference>
) -> &mut Self
Set the reference message this message is a reply to.
sourcepub fn components<F>(&mut self, f: F) -> &mut Self where
F: FnOnce(&mut CreateComponents) -> &mut CreateComponents,
pub fn components<F>(&mut self, f: F) -> &mut Self where
F: FnOnce(&mut CreateComponents) -> &mut CreateComponents,
Creates components for this message.
sourcepub fn set_components(&mut self, components: CreateComponents) -> &mut Self
pub fn set_components(&mut self, components: CreateComponents) -> &mut Self
Sets the components of this message.
sourcepub fn flags(&mut self, flags: MessageFlags) -> &mut Self
pub fn flags(&mut self, flags: MessageFlags) -> &mut Self
Sets the flags for the message.
sourcepub fn sticker_id(&mut self, sticker_id: impl Into<StickerId>) -> &mut Self
pub fn sticker_id(&mut self, sticker_id: impl Into<StickerId>) -> &mut Self
Sets a single sticker ID to include in the message.
Note: This will replace all existing stickers. Use
Self::add_sticker_id()
to add an additional sticker.
sourcepub fn add_sticker_id(&mut self, sticker_id: impl Into<StickerId>) -> &mut Self
pub fn add_sticker_id(&mut self, sticker_id: impl Into<StickerId>) -> &mut Self
Add a sticker ID for the message.
Note: There can be a maximum of 3 stickers in a message.
Note: This will keep all existing stickers. Use
Self::set_sticker_ids()
to replace existing stickers.
sourcepub fn add_sticker_ids<T: Into<StickerId>, It: IntoIterator<Item = T>>(
&mut self,
sticker_ids: It
) -> &mut Self
pub fn add_sticker_ids<T: Into<StickerId>, It: IntoIterator<Item = T>>(
&mut self,
sticker_ids: It
) -> &mut Self
Add multiple sticker IDs for the message.
Note: There can be a maximum of 3 stickers in a message.
Note: This will keep all existing stickers. Use
Self::set_sticker_ids()
to replace existing stickers.
sourcepub fn set_sticker_ids<T: Into<StickerId>, It: IntoIterator<Item = T>>(
&mut self,
sticker_ids: It
) -> &mut Self
pub fn set_sticker_ids<T: Into<StickerId>, It: IntoIterator<Item = T>>(
&mut self,
sticker_ids: It
) -> &mut Self
Sets a list of sticker IDs to include in the message.
Note: There can be a maximum of 3 stickers in a message.
Note: This will replace all existing stickers. Use
Self::add_sticker_id()
or Self::add_sticker_ids()
to keep
existing stickers.
Trait Implementations
sourceimpl<'a> Clone for CreateMessage<'a>
impl<'a> Clone for CreateMessage<'a>
sourcefn clone(&self) -> CreateMessage<'a>
fn clone(&self) -> CreateMessage<'a>
Returns a copy of the value. Read more
1.0.0 · sourcefn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from source
. Read more
sourceimpl<'a> Debug for CreateMessage<'a>
impl<'a> Debug for CreateMessage<'a>
sourceimpl<'a> Default for CreateMessage<'a>
impl<'a> Default for CreateMessage<'a>
sourcefn default() -> CreateMessage<'a>
fn default() -> CreateMessage<'a>
Auto Trait Implementations
impl<'a> !RefUnwindSafe for CreateMessage<'a>
impl<'a> Send for CreateMessage<'a>
impl<'a> Sync for CreateMessage<'a>
impl<'a> Unpin for CreateMessage<'a>
impl<'a> !UnwindSafe for CreateMessage<'a>
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> Instrument for T
impl<T> Instrument for T
sourcefn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
sourcefn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
sourceimpl<T> ToOwned for T where
T: Clone,
impl<T> ToOwned for T where
T: Clone,
type Owned = T
type Owned = T
The resulting type after obtaining ownership.
sourcefn clone_into(&self, target: &mut T)
fn clone_into(&self, target: &mut T)
toowned_clone_into
)Uses borrowed data to replace owned data, usually by cloning. Read more
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
fn vzip(self) -> V
sourceimpl<T> WithSubscriber for T
impl<T> WithSubscriber for T
sourcefn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> where
S: Into<Dispatch>,
fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> where
S: Into<Dispatch>,
Attaches the provided Subscriber
to this type, returning a
WithDispatch
wrapper. Read more
sourcefn with_current_subscriber(self) -> WithDispatch<Self>
fn with_current_subscriber(self) -> WithDispatch<Self>
Attaches the current default Subscriber
to this type, returning a
WithDispatch
wrapper. Read more