pub struct EditAttachments { /* private fields */ }
Expand description
You can add new attachments and edit existing ones using this builder.
When this builder is not supplied in a message edit, Discord keeps the attachments intact.
However, as soon as a builder is supplied, Discord removes all attachments from the message. If
you want to keep old attachments, you must specify this either using Self::keep_all
, or
individually for each attachment using Self::keep
.
§Examples
§Removing all attachments
msg.edit(ctx, EditMessage::new().attachments(EditAttachments::new())).await?;
§Adding a new attachment without deleting existing attachments
msg.edit(ctx, EditMessage::new().attachments(
EditAttachments::keep_all(&msg).add(my_attachment)
)).await?;
§Delete all but the first attachment
msg.edit(ctx, EditMessage::new().attachments(
EditAttachments::new().keep(msg.attachments[0].id)
)).await?;
§Delete only the first attachment
msg.edit(ctx, EditMessage::new().attachments(
EditAttachments::keep_all(&msg).remove(msg.attachments[0].id)
)).await?;
§Notes
Internally, this type is used not just for message editing endpoints, but also for message creation endpoints.
Implementations§
Source§impl EditAttachments
impl EditAttachments
Sourcepub fn new() -> Self
pub fn new() -> Self
An empty attachments builder.
Existing attachments are not kept by default, either. See Self::keep_all()
or
Self::keep()
.
Sourcepub fn keep_all(msg: &Message) -> Self
pub fn keep_all(msg: &Message) -> Self
Creates a new attachments builder that keeps all existing attachments.
Shorthand for Self::new()
and calling Self::keep()
for every AttachmentId
in
Message::attachments
.
If you only want to keep a subset of attachments from the message, either implement this
method manually, or use Self::remove()
.
Note: this EditAttachments must be run on the same message as is supplied here, or else Discord will throw an error!
Sourcepub fn keep(self, id: AttachmentId) -> Self
pub fn keep(self, id: AttachmentId) -> Self
This method adds an existing attachment to the list of attachments that are kept after editing.
Opposite of Self::remove
.
Sourcepub fn remove(self, id: AttachmentId) -> Self
pub fn remove(self, id: AttachmentId) -> Self
This method removes an existing attachment from the list of attachments that are kept after editing.
Opposite of Self::keep
.
Sourcepub fn add(self, attachment: CreateAttachment) -> Self
pub fn add(self, attachment: CreateAttachment) -> Self
Adds a new attachment to the attachment list.
Trait Implementations§
Source§impl Clone for EditAttachments
impl Clone for EditAttachments
Source§fn clone(&self) -> EditAttachments
fn clone(&self) -> EditAttachments
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read more