From 3652f054ee772b8899e7be2d9c773181aba40f8b Mon Sep 17 00:00:00 2001 From: Jaw0r3k Date: Wed, 16 Aug 2023 13:54:03 +0200 Subject: [PATCH 1/3] feat(Client): deleteWebhook method --- packages/discord.js/src/client/Client.js | 17 +++++++++++++++++ packages/discord.js/typings/index.d.ts | 6 ++++++ 2 files changed, 23 insertions(+) diff --git a/packages/discord.js/src/client/Client.js b/packages/discord.js/src/client/Client.js index 07d15c973f6d..dc2b8368057f 100644 --- a/packages/discord.js/src/client/Client.js +++ b/packages/discord.js/src/client/Client.js @@ -253,6 +253,23 @@ class Client extends BaseClient { this.rest.setToken(null); } + /** + * Options used when deleting a webhook from Discord. + * @typedef {Object} WebhookDeleteOptions + * @property {string} [token] Token of the webhook + * @property {string} [reason] The reason for deleting the webhook + */ + + /** + * Deletes a webhook. + * @param {Snowflake} id The webhook's id + * @param {WebhookDeleteOptions} [options] Options for deleting the webhook + * @returns {Promise} + */ + async deleteWebhook(id, { token, reason } = {}) { + await this.rest.delete(Routes.webhook(id, token), { auth: token === undefined, reason }); + } + /** * Options used when fetching an invite from Discord. * @typedef {Object} ClientFetchInviteOptions diff --git a/packages/discord.js/typings/index.d.ts b/packages/discord.js/typings/index.d.ts index 169aa439c25a..c656db2c98c0 100644 --- a/packages/discord.js/typings/index.d.ts +++ b/packages/discord.js/typings/index.d.ts @@ -969,6 +969,7 @@ export class Client extends BaseClient { public voice: ClientVoiceManager; public ws: WebSocketManager; public destroy(): Promise; + public deleteWebhook(id: Snowflake, options?: WebhookDeleteOptions): Promise; public fetchGuildPreview(guild: GuildResolvable): Promise; public fetchInvite(invite: InviteResolvable, options?: ClientFetchInviteOptions): Promise; public fetchGuildTemplate(template: GuildTemplateResolvable): Promise; @@ -6397,6 +6398,11 @@ export interface WebhookClientDataURL { export type WebhookClientOptions = Pick; +export interface WebhookDeleteOptions { + token?: string; + reason?: string; +} + export interface WebhookEditOptions { name?: string; avatar?: BufferResolvable | null; From 5de608a576a0b390e45074bed16b8dd47710b38e Mon Sep 17 00:00:00 2001 From: Jaw0r3k Date: Wed, 16 Aug 2023 14:16:50 +0200 Subject: [PATCH 2/3] Update packages/discord.js/src/client/Client.js Co-authored-by: Jiralite <33201955+Jiralite@users.noreply.github.com> --- packages/discord.js/src/client/Client.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/discord.js/src/client/Client.js b/packages/discord.js/src/client/Client.js index dc2b8368057f..746197088642 100644 --- a/packages/discord.js/src/client/Client.js +++ b/packages/discord.js/src/client/Client.js @@ -254,7 +254,7 @@ class Client extends BaseClient { } /** - * Options used when deleting a webhook from Discord. + * Options used for deleting a webhook. * @typedef {Object} WebhookDeleteOptions * @property {string} [token] Token of the webhook * @property {string} [reason] The reason for deleting the webhook From 85d86aaa30608a89346866194dc196c59cc7823f Mon Sep 17 00:00:00 2001 From: Jaw0r3k Date: Wed, 16 Aug 2023 14:26:48 +0200 Subject: [PATCH 3/3] chore: suggested changes Co-authored-by: Jiralite <33201955+Jiralite@users.noreply.github.com> --- packages/discord.js/src/client/Client.js | 2 +- packages/discord.js/src/structures/Webhook.js | 7 ++----- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/packages/discord.js/src/client/Client.js b/packages/discord.js/src/client/Client.js index 746197088642..80719e864786 100644 --- a/packages/discord.js/src/client/Client.js +++ b/packages/discord.js/src/client/Client.js @@ -267,7 +267,7 @@ class Client extends BaseClient { * @returns {Promise} */ async deleteWebhook(id, { token, reason } = {}) { - await this.rest.delete(Routes.webhook(id, token), { auth: token === undefined, reason }); + await this.rest.delete(Routes.webhook(id, token), { auth: !token, reason }); } /** diff --git a/packages/discord.js/src/structures/Webhook.js b/packages/discord.js/src/structures/Webhook.js index efc02218e376..5a0a3137588e 100644 --- a/packages/discord.js/src/structures/Webhook.js +++ b/packages/discord.js/src/structures/Webhook.js @@ -366,11 +366,8 @@ class Webhook { * @param {string} [reason] Reason for deleting this webhook * @returns {Promise} */ - async delete(reason) { - await this.client.rest.delete(Routes.webhook(this.id, this.token), { - reason, - auth: !this.token, - }); + delete(reason) { + return this.client.deleteWebhook(this.id, { token: this.token, reason }); } /**