pub struct EditMessage { /* private fields */ }
Available on crate feature builder only.
Expand description

A builder to specify the fields to edit in an existing message.

§Examples

Editing the content of a Message to "hello":


let builder = EditMessage::new().content("hello");
message.edit(ctx, builder).await?;

Discord docs

Implementations§

source§

impl EditMessage

source

pub fn new() -> Self

Equivalent to Self::default.

source

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.

source

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.

source

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.

source

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.

source

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.

source

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?;
source

pub fn allowed_mentions(self, allowed_mentions: CreateAllowedMentions) -> Self

Set the allowed mentions for the message.

source

pub fn components(self, components: Vec<CreateActionRow>) -> Self

Sets the components of this message.

source

pub fn button(self, button: CreateButton) -> Self

Adds a clickable button to this message.

Convenience method that wraps Self::components. Arranges buttons in action rows automatically.

source

pub fn select_menu(self, select_menu: CreateSelectMenu) -> Self

Adds an interactive select menu to this message.

Convenience method that wraps Self::components.

source

pub fn flags(self, flags: MessageFlags) -> Self

Sets the flags for the message.

source

pub fn attachments(self, attachments: EditAttachments) -> Self

Sets attachments, see EditAttachments for more details.

source

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.

source

pub fn keep_existing_attachment(self, id: AttachmentId) -> Self

Shorthand for EditAttachments::keep.

source

pub fn remove_existing_attachment(self, id: AttachmentId) -> Self

Shorthand for EditAttachments::remove.

source

pub fn remove_all_attachments(self) -> Self

Shorthand for calling Self::attachments with EditAttachments::new.

Trait Implementations§

source§

impl Builder for EditMessage

Available on crate feature http only.
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,

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.

§

type Context<'ctx> = (ChannelId, MessageId, Option<UserId>)

Additional data that’s only required when sending a request off to the API.
§

type Built = Message

source§

impl Clone for EditMessage

source§

fn clone(&self) -> EditMessage

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for EditMessage

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Default for EditMessage

source§

fn default() -> EditMessage

Returns the “default value” for a type. Read more
source§

impl PartialEq for EditMessage

source§

fn eq(&self, other: &EditMessage) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl Serialize for EditMessage

source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
source§

impl StructuralPartialEq for EditMessage

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> CloneDebuggableStorage for T

source§

impl<T> CloneableStorage for T
where T: Any + Send + Sync + Clone,

source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T> Instrument for T

source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> Same for T

§

type Output = T

Should always be Self
source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

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

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

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

§

fn vzip(self) -> V

source§

impl<T> WithSubscriber for T

source§

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
source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

impl<T> DebuggableStorage for T
where T: Any + Send + Sync + Debug,