From b3de175f1357f3842584699352ea36492dab6dff Mon Sep 17 00:00:00 2001 From: Fleny Date: Sun, 27 Apr 2025 09:42:51 +0200 Subject: [PATCH] feat(types,rest,bot): Add `with_components` to webhooks (#4152) * Add with_components to webhook execute and edit * Fix query param building * update comments --- packages/bot/src/helpers.ts | 2 +- packages/rest/src/routes.ts | 4 +++- packages/rest/src/types.ts | 2 +- packages/rest/src/typings/routes.ts | 4 ++-- packages/types/src/discordeno.ts | 15 ++++++++++++++- 5 files changed, 21 insertions(+), 6 deletions(-) diff --git a/packages/bot/src/helpers.ts b/packages/bot/src/helpers.ts index 6822689bb..85167a201 100644 --- a/packages/bot/src/helpers.ts +++ b/packages/bot/src/helpers.ts @@ -948,7 +948,7 @@ export type BotHelpers Promise> editWebhookWithToken: ( webhookId: BigString, diff --git a/packages/rest/src/routes.ts b/packages/rest/src/routes.ts index fa2d11e0c..22d15aa00 100644 --- a/packages/rest/src/routes.ts +++ b/packages/rest/src/routes.ts @@ -13,6 +13,7 @@ export function createRoutes(): RestRoutes { if (options) { if (options.threadId) url += `thread_id=${options.threadId}` + if (options.withComponents) url += `&with_components=${options.withComponents}` } return url @@ -31,7 +32,8 @@ export function createRoutes(): RestRoutes { if (options) { if (options?.wait !== undefined) url += `wait=${options.wait.toString()}` - if (options.threadId) url += `thread_id=${options.threadId}` + if (options.threadId) url += `&thread_id=${options.threadId}` + if (options.withComponents) url += `&with_components=${options.withComponents}` } return url diff --git a/packages/rest/src/types.ts b/packages/rest/src/types.ts index d3a37f5bd..c67046a72 100644 --- a/packages/rest/src/types.ts +++ b/packages/rest/src/types.ts @@ -1483,7 +1483,7 @@ export interface RestManager { webhookId: BigString, token: string, messageId: BigString, - options: InteractionCallbackData & { threadId?: BigString }, + options: InteractionCallbackData & { threadId?: BigString; withComponents?: boolean }, ) => Promise> /** * Edits a webhook using the webhook token, thereby bypassing the need for authentication + permissions. diff --git a/packages/rest/src/typings/routes.ts b/packages/rest/src/typings/routes.ts index 8dbb6df76..e05f58a87 100644 --- a/packages/rest/src/typings/routes.ts +++ b/packages/rest/src/typings/routes.ts @@ -33,9 +33,9 @@ export interface RestRoutes { /** Route for webhook with a id. */ id: (webhookId: BigString) => string /** Route for handling a webhook with a token. */ - webhook: (webhookId: BigString, token: string, options?: { wait?: boolean; threadId?: BigString }) => string + webhook: (webhookId: BigString, token: string, options?: { wait?: boolean; threadId?: BigString; withComponents?: boolean }) => string /** Route for handling a message that was sent through a webhook. */ - message: (webhookId: BigString, token: string, messageId: BigString, options?: { threadId?: BigString }) => string + message: (webhookId: BigString, token: string, messageId: BigString, options?: { threadId?: BigString; withComponents?: boolean }) => string } /** Routes for channel related endpoints. */ channels: { diff --git a/packages/types/src/discordeno.ts b/packages/types/src/discordeno.ts index 4326d9695..69ae10053 100644 --- a/packages/types/src/discordeno.ts +++ b/packages/types/src/discordeno.ts @@ -1062,6 +1062,13 @@ export interface ExecuteWebhook { wait?: boolean /** Send a message to the specified thread within a webhook's channel. The thread will automatically be unarchived. */ threadId?: BigString + /** + * Whether to respect the `components` field of the request. + * When enabled, allows application-owned webhooks to use all components and non-owned webhooks to use non-interactive components. + * + * @default false + */ + withComponents?: boolean /** Name of the thread to create (target channel has to be type of forum channel) */ threadName?: string /** Array of tag ids to apply to the thread (requires the webhook channel to be a forum or media channel) */ @@ -1080,7 +1087,13 @@ export interface ExecuteWebhook { embeds?: Camelize[] /** Allowed mentions for the message */ allowedMentions?: AllowedMentions - /** the components to include with the message */ + /** + * The components to include with the message + * + * @remarks + * Application-owned webhooks can always send components. + * Non-application-owned webhooks cannot send interactive components, and the `components` field will be gnored unless they set the `with_components` query param. + */ components?: MessageComponents /** A poll object */ poll?: CreatePoll