Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 18 additions & 2 deletions src/builder/execute_webhook.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ pub struct ExecuteWebhook {

#[serde(skip)]
thread_id: Option<ChannelId>,
#[serde(skip)]
with_components: Option<bool>,
}

impl ExecuteWebhook {
Expand Down Expand Up @@ -222,7 +224,10 @@ impl ExecuteWebhook {
/// the webhook's `kind` field is set to [`WebhookType::Application`], or it was created by an
/// application (and has kind [`WebhookType::Incoming`]).
///
/// [`WebhookType::Application`]: crate::model::webhook::WebhookType
/// If [`Self::with_components`] is set, non-interactive components can be used on non
/// application-owned webhooks.
///
/// [`WebhookType::Application`]: crate::model::webhook::WebhookT
/// [`WebhookType::Incoming`]: crate::model::webhook::WebhookType
pub fn components(mut self, components: Vec<CreateActionRow>) -> Self {
self.components = Some(components);
Expand Down Expand Up @@ -337,6 +342,12 @@ impl ExecuteWebhook {
self.thread_name = Some(thread_name);
self
}

/// Allows sending non interactive components on non application owned webhooks.
pub fn with_components(mut self, with_components: bool) -> Self {
self.with_components = Some(with_components);
self
}
}

#[cfg(feature = "http")]
Expand Down Expand Up @@ -367,6 +378,11 @@ impl Builder for ExecuteWebhook {
self.allowed_mentions.clone_from(&http.default_allowed_mentions);
}

http.execute_webhook(ctx.0, self.thread_id, ctx.1, ctx.2, files, &self).await
if self.with_components.unwrap_or_default() {
http.execute_webhook_with_components(ctx.0, self.thread_id, ctx.1, ctx.2, files, &self)
.await
} else {
http.execute_webhook(ctx.0, self.thread_id, ctx.1, ctx.2, files, &self).await
}
}
}
34 changes: 34 additions & 0 deletions src/http/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2572,12 +2572,46 @@ impl Http {
wait: bool,
files: Vec<CreateAttachment>,
map: &impl serde::Serialize,
) -> Result<Option<Message>> {
self.execute_webhook_(webhook_id, thread_id, token, wait, files, map, false).await
}

/// Same as [`Self::execute_webhook`] but allows sending non interactive components on non
/// app-owned webhooks.
///
/// [Discord docs]: https://discord.com/developers/docs/resources/webhook#execute-webhook-query-string-params
pub async fn execute_webhook_with_components(
&self,
webhook_id: WebhookId,
thread_id: Option<ChannelId>,
token: &str,
wait: bool,
files: Vec<CreateAttachment>,
map: &impl serde::Serialize,
) -> Result<Option<Message>> {
self.execute_webhook_(webhook_id, thread_id, token, wait, files, map, false).await
}

#[expect(clippy::too_many_arguments)]
async fn execute_webhook_(
&self,
webhook_id: WebhookId,
thread_id: Option<ChannelId>,
token: &str,
wait: bool,
files: Vec<CreateAttachment>,
map: &impl serde::Serialize,
with_components: bool,
) -> Result<Option<Message>> {
let mut params = vec![("wait", wait.to_string())];
if let Some(thread_id) = thread_id {
params.push(("thread_id", thread_id.to_string()));
}

if with_components {
params.push(("with_components", with_components.to_string()));
}

let mut request = Request {
body: None,
multipart: None,
Expand Down
Loading