Skip to content

Commit 5bfce60

Browse files
authored
Add flags to EditWebhookMessage and EditInteractionResponse (#3380)
This commit adds the `flags` field/setter to `EditWebhookMessage` and `EditInteractionResponse`. It also modifies `EditMessage::suppress_embeds` because the `IS_COMPONENTS_V2` flag can also be set there now. This allows upgrading webhook messages and interaction responses to components V2 in an edit. This appears to be required when deferring interaction responses.
1 parent 52d60a9 commit 5bfce60

File tree

3 files changed

+17
-5
lines changed

3 files changed

+17
-5
lines changed

src/builder/edit_interaction_response.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,11 @@ impl EditInteractionResponse {
7676
}
7777
super::button_and_select_menu_convenience_methods!(self.0.components);
7878

79+
/// Sets the flags for the message.
80+
pub fn flags(self, flags: MessageFlags) -> Self {
81+
Self(self.0.flags(flags))
82+
}
83+
7984
/// Sets attachments, see [`EditAttachments`] for more details.
8085
pub fn attachments(self, attachments: EditAttachments) -> Self {
8186
Self(self.0.attachments(attachments))

src/builder/edit_message.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -153,11 +153,10 @@ impl EditMessage {
153153
/// # Ok(()) }
154154
/// ```
155155
pub fn suppress_embeds(mut self, suppress: bool) -> Self {
156-
// At time of writing, only `SUPPRESS_EMBEDS` can be set/unset when editing messages. See
157-
// for details: https://discord.com/developers/docs/resources/channel#edit-message-jsonform-params
158-
let flags = if suppress { MessageFlags::SUPPRESS_EMBEDS } else { MessageFlags::empty() };
159-
160-
self.flags = Some(flags);
156+
// See for details: https://discord.com/developers/docs/resources/message#edit-message-jsonform-params
157+
self.flags
158+
.get_or_insert(MessageFlags::empty())
159+
.set(MessageFlags::SUPPRESS_EMBEDS, suppress);
161160
self
162161
}
163162

src/builder/edit_webhook_message.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ pub struct EditWebhookMessage {
2626
#[serde(skip_serializing_if = "Option::is_none")]
2727
embeds: Option<Vec<CreateEmbed>>,
2828
#[serde(skip_serializing_if = "Option::is_none")]
29+
flags: Option<MessageFlags>,
30+
#[serde(skip_serializing_if = "Option::is_none")]
2931
allowed_mentions: Option<CreateAllowedMentions>,
3032
#[serde(skip_serializing_if = "Option::is_none")]
3133
pub(crate) components: Option<Vec<CreateActionRow>>,
@@ -131,6 +133,12 @@ impl EditWebhookMessage {
131133
}
132134
super::button_and_select_menu_convenience_methods!(self.components);
133135

136+
/// Sets the flags for the message.
137+
pub fn flags(mut self, flags: MessageFlags) -> Self {
138+
self.flags = Some(flags);
139+
self
140+
}
141+
134142
/// Sets attachments, see [`EditAttachments`] for more details.
135143
pub fn attachments(mut self, attachments: EditAttachments) -> Self {
136144
self.attachments = Some(attachments);

0 commit comments

Comments
 (0)