1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
#[cfg(feature = "http")]
use super::Builder;
use super::{
CreateActionRow,
CreateAllowedMentions,
CreateAttachment,
CreateEmbed,
EditAttachments,
EditWebhookMessage,
};
#[cfg(feature = "http")]
use crate::http::CacheHttp;
#[cfg(feature = "http")]
use crate::internal::prelude::*;
use crate::model::prelude::*;
/// [Discord docs](https://discord.com/developers/docs/interactions/receiving-and-responding#edit-original-interaction-response)
#[derive(Clone, Debug, Default, Serialize)]
#[must_use]
pub struct EditInteractionResponse(EditWebhookMessage);
impl EditInteractionResponse {
/// Equivalent to [`Self::default`].
pub fn new() -> Self {
Self::default()
}
/// Set the content of the message.
///
/// **Note**: Message contents must be under 2000 unicode code points.
#[inline]
pub fn content(self, content: impl Into<String>) -> Self {
Self(self.0.content(content))
}
/// Adds an embed for the message.
///
/// Embeds from the original message are reset when adding new embeds and must be re-added.
pub fn add_embed(self, embed: CreateEmbed) -> Self {
Self(self.0.add_embed(embed))
}
/// Adds multiple embeds to the message.
///
/// Embeds from the original message are reset when adding new embeds and must be re-added.
pub fn add_embeds(self, embeds: Vec<CreateEmbed>) -> Self {
Self(self.0.add_embeds(embeds))
}
/// Sets a single embed to include in the message
///
/// Calling this will overwrite the embed list. To append embeds, call [`Self::add_embed`]
/// instead.
pub fn embed(self, embed: CreateEmbed) -> Self {
Self(self.0.embed(embed))
}
/// Sets the embeds for the message.
///
/// **Note**: You can only have up to 10 embeds per message.
///
/// Calling this will overwrite the embed list. To append embeds, call [`Self::add_embeds`]
/// instead.
pub fn embeds(self, embeds: Vec<CreateEmbed>) -> Self {
Self(self.0.embeds(embeds))
}
/// Set the allowed mentions for the message.
pub fn allowed_mentions(self, allowed_mentions: CreateAllowedMentions) -> Self {
Self(self.0.allowed_mentions(allowed_mentions))
}
/// Sets the components of this message.
pub fn components(self, components: Vec<CreateActionRow>) -> Self {
Self(self.0.components(components))
}
super::button_and_select_menu_convenience_methods!(self.0.components);
/// Sets the flags for the message.
pub fn flags(self, flags: MessageFlags) -> Self {
Self(self.0.flags(flags))
}
/// Sets attachments, see [`EditAttachments`] for more details.
pub fn attachments(self, attachments: EditAttachments) -> Self {
Self(self.0.attachments(attachments))
}
/// Adds a new attachment to the message.
///
/// Resets existing attachments. See the documentation for [`EditAttachments`] for details.
pub fn new_attachment(self, attachment: CreateAttachment) -> Self {
Self(self.0.new_attachment(attachment))
}
/// Shorthand for [`EditAttachments::keep`].
pub fn keep_existing_attachment(self, id: AttachmentId) -> Self {
Self(self.0.keep_existing_attachment(id))
}
/// Shorthand for calling [`Self::attachments`] with [`EditAttachments::new`].
pub fn clear_attachments(self) -> Self {
Self(self.0.clear_attachments())
}
}
#[cfg(feature = "http")]
#[async_trait::async_trait]
impl Builder for EditInteractionResponse {
type Context<'ctx> = &'ctx str;
type Built = Message;
/// Edits the initial interaction response. Does not work for ephemeral messages.
///
/// The `application_id` used will usually be the bot's [`UserId`], except if the bot is very
/// old.
///
/// **Note**: Message contents must be under 2000 unicode code points, and embeds must be under
/// 6000 code points.
///
/// # Errors
///
/// Returns an [`Error::Model`] if the message content is too long. May also return an
/// [`Error::Http`] if the API returns an error, or an [`Error::Json`] if there is an error in
/// deserializing the API response.
async fn execute(
mut self,
cache_http: impl CacheHttp,
ctx: Self::Context<'_>,
) -> Result<Self::Built> {
self.0.check_length()?;
let files = self.0.attachments.as_mut().map_or(Vec::new(), |a| a.take_files());
cache_http.http().edit_original_interaction_response(ctx, &self, files).await
}
}