pub struct EditMessage { /* private fields */ }
Expand description
Implementations§
Source§impl EditMessage
impl EditMessage
Sourcepub fn new() -> Self
pub fn new() -> Self
Equivalent to Self::default
.
Sourcepub fn content(self, content: impl Into<String>) -> Self
pub fn content(self, content: impl Into<String>) -> Self
Set the content of the message.
Note: Message contents must be under 2000 unicode code points.
Sourcepub fn add_embed(self, embed: CreateEmbed) -> Self
pub fn add_embed(self, embed: CreateEmbed) -> Self
Add an embed for the message.
Note: This will keep all existing embeds. Use Self::embed()
to replace existing
embeds.
Sourcepub fn add_embeds(self, embeds: Vec<CreateEmbed>) -> Self
pub fn add_embeds(self, embeds: Vec<CreateEmbed>) -> Self
Add multiple embeds for the message.
Note: This will keep all existing embeds. Use Self::embeds()
to replace existing
embeds.
Sourcepub fn embed(self, embed: CreateEmbed) -> Self
pub fn embed(self, embed: CreateEmbed) -> Self
Set an embed for the message.
Note: This will replace all existing embeds. Use Self::add_embed()
to keep existing
embeds.
Sourcepub fn embeds(self, embeds: Vec<CreateEmbed>) -> Self
pub fn embeds(self, embeds: Vec<CreateEmbed>) -> Self
Set multiple embeds for the message.
Note: This will replace all existing embeds. Use Self::add_embeds()
to keep existing
embeds.
Sourcepub fn suppress_embeds(self, suppress: bool) -> Self
pub fn suppress_embeds(self, suppress: bool) -> Self
Suppress or unsuppress embeds in the message, this includes those generated by Discord themselves.
If this is sent directly after posting the message, there is a small chance Discord hasn’t yet fully parsed the contained links and generated the embeds, so this embed suppression request has no effect. To mitigate this, you can defer the embed suppression until the embeds have loaded:
use std::time::Duration;
use futures::StreamExt;
let mut msg = channel_id.say(ctx, "<link that spawns an embed>").await?;
// When the embed appears, a MessageUpdate event is sent and we suppress the embed.
// No MessageUpdate event is sent if the message contains no embeddable link or if the link
// has been posted before and is still cached in Discord's servers (in which case the
// embed appears immediately), no MessageUpdate event is sent. To not wait forever in those
// cases, a timeout of 2000ms was added.
let msg_id = msg.id;
let mut message_updates = serenity::collector::collect(&ctx.shard, move |ev| match ev {
Event::MessageUpdate(x) if x.id == msg_id => Some(()),
_ => None,
});
let _ = tokio::time::timeout(Duration::from_millis(2000), message_updates.next()).await;
msg.edit(&ctx, EditMessage::new().suppress_embeds(true)).await?;
Sourcepub fn allowed_mentions(self, allowed_mentions: CreateAllowedMentions) -> Self
pub fn allowed_mentions(self, allowed_mentions: CreateAllowedMentions) -> Self
Set the allowed mentions for the message.
Sourcepub fn components(self, components: Vec<CreateActionRow>) -> Self
pub fn components(self, components: Vec<CreateActionRow>) -> Self
Sets the components of this message.
Adds a clickable button to this message.
Convenience method that wraps Self::components
. Arranges buttons in action rows
automatically.
Adds an interactive select menu to this message.
Convenience method that wraps Self::components
.
Sourcepub fn flags(self, flags: MessageFlags) -> Self
pub fn flags(self, flags: MessageFlags) -> Self
Sets the flags for the message.
Sourcepub fn attachments(self, attachments: EditAttachments) -> Self
pub fn attachments(self, attachments: EditAttachments) -> Self
Sets attachments, see EditAttachments
for more details.
Sourcepub fn new_attachment(self, attachment: CreateAttachment) -> Self
pub fn new_attachment(self, attachment: CreateAttachment) -> Self
Adds a new attachment to the message.
Resets existing attachments. See the documentation for EditAttachments
for details.
Sourcepub fn keep_existing_attachment(self, id: AttachmentId) -> Self
pub fn keep_existing_attachment(self, id: AttachmentId) -> Self
Shorthand for EditAttachments::keep
.
Sourcepub fn remove_existing_attachment(self, id: AttachmentId) -> Self
pub fn remove_existing_attachment(self, id: AttachmentId) -> Self
Shorthand for EditAttachments::remove
.
Sourcepub fn remove_all_attachments(self) -> Self
pub fn remove_all_attachments(self) -> Self
Shorthand for calling Self::attachments
with EditAttachments::new
.
Trait Implementations§
Source§impl Builder for EditMessage
impl Builder for EditMessage
Source§fn execute<'life0, 'async_trait>(
self,
cache_http: impl 'async_trait + CacheHttp,
ctx: Self::Context<'life0>,
) -> Pin<Box<dyn Future<Output = Result<Self::Built>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn execute<'life0, 'async_trait>(
self,
cache_http: impl 'async_trait + CacheHttp,
ctx: Self::Context<'life0>,
) -> Pin<Box<dyn Future<Output = Result<Self::Built>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Edits a message in the channel.
Note: Message contents must be under 2000 unicode code points, and embeds must be under 6000 code points.
Note: Requires that the current user be the author of the message. Other users can only
call Self::suppress_embeds
, but additionally require the Manage Messages permission
to do so.
Note: If any embeds or attachments are set, they will overwrite the existing contents
of the message, deleting existing embeds and attachments. Preserving them requires calling
Self::keep_existing_attachment
in the case of attachments. In the case of embeds,
duplicate copies of the existing embeds must be sent. Luckily, CreateEmbed
implements
From<Embed>
, so one can simply call embed.into()
.
§Errors
Returns a ModelError::MessageTooLong
if the message contents are over the above limits.
Returns Error::Http
if the user lacks permission, as well as if invalid data is given.
Source§type Context<'ctx> = (ChannelId, MessageId, Option<UserId>)
type Context<'ctx> = (ChannelId, MessageId, Option<UserId>)
type Built = Message
Source§impl Clone for EditMessage
impl Clone for EditMessage
Source§fn clone(&self) -> EditMessage
fn clone(&self) -> EditMessage
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read more