From 0f1ee47dec7b338497a52df9e7ccc26bdb73c9db Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aura=20Rom=C3=A1n?= Date: Sun, 20 Aug 2023 11:21:31 +0200 Subject: [PATCH 1/3] fix(Webhook): do not call `client.deleteWebhook` in `delete` Partially reverts #9777 which caused a regression (#9785) when using `WebhookClient` --- packages/discord.js/src/structures/Webhook.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/packages/discord.js/src/structures/Webhook.js b/packages/discord.js/src/structures/Webhook.js index 738d9e765b03..64f258614a75 100644 --- a/packages/discord.js/src/structures/Webhook.js +++ b/packages/discord.js/src/structures/Webhook.js @@ -367,8 +367,11 @@ class Webhook { * @param {string} [reason] Reason for deleting this webhook * @returns {Promise} */ - delete(reason) { - return this.client.deleteWebhook(this.id, { token: this.token, reason }); + async delete(reason) { + await this.client.rest.delete(Routes.webhook(this.id, this.token), { + reason, + auth: !this.token, + }); } /** From 04e61704469af81e6c9553434538a1d1e660c2b1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aura=20Rom=C3=A1n?= Date: Sun, 20 Aug 2023 11:27:01 +0200 Subject: [PATCH 2/3] chore: add comment Co-Authored-By: Souji --- packages/discord.js/src/structures/Webhook.js | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/discord.js/src/structures/Webhook.js b/packages/discord.js/src/structures/Webhook.js index 64f258614a75..19bb22a2303f 100644 --- a/packages/discord.js/src/structures/Webhook.js +++ b/packages/discord.js/src/structures/Webhook.js @@ -368,6 +368,7 @@ class Webhook { * @returns {Promise} */ async delete(reason) { + // This doesn't call `Client`'s `deleteWebhook` method because `WebhookClient` lacks it, see #9785. await this.client.rest.delete(Routes.webhook(this.id, this.token), { reason, auth: !this.token, From 0b053c91d7c28035f4261b26725e0d0ed9b98a33 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aura=20Rom=C3=A1n?= Date: Sun, 5 Nov 2023 19:09:57 +0100 Subject: [PATCH 3/3] fix: move `deleteWebhook` from `Client` to `BaseClient` --- packages/discord.js/src/client/BaseClient.js | 18 ++++++++++++++++++ packages/discord.js/src/client/Client.js | 17 ----------------- packages/discord.js/src/structures/Webhook.js | 8 ++------ 3 files changed, 20 insertions(+), 23 deletions(-) diff --git a/packages/discord.js/src/client/BaseClient.js b/packages/discord.js/src/client/BaseClient.js index 631748c92506..5f8e492f0bf1 100644 --- a/packages/discord.js/src/client/BaseClient.js +++ b/packages/discord.js/src/client/BaseClient.js @@ -2,6 +2,7 @@ const EventEmitter = require('node:events'); const { REST } = require('@discordjs/rest'); +const { Routes } = require('discord-api-types/v10'); const { DiscordjsTypeError, ErrorCodes } = require('../errors'); const Options = require('../util/Options'); const { mergeDefault, flatten } = require('../util/Util'); @@ -48,6 +49,23 @@ class BaseClient extends EventEmitter { this.rest.clearHandlerSweeper(); } + /** + * 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 + */ + + /** + * 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, reason }); + } + /** * Increments max listeners by one, if they are not zero. * @private diff --git a/packages/discord.js/src/client/Client.js b/packages/discord.js/src/client/Client.js index 80719e864786..07d15c973f6d 100644 --- a/packages/discord.js/src/client/Client.js +++ b/packages/discord.js/src/client/Client.js @@ -253,23 +253,6 @@ class Client extends BaseClient { this.rest.setToken(null); } - /** - * 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 - */ - - /** - * 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, reason }); - } - /** * Options used when fetching an invite from Discord. * @typedef {Object} ClientFetchInviteOptions diff --git a/packages/discord.js/src/structures/Webhook.js b/packages/discord.js/src/structures/Webhook.js index 19bb22a2303f..738d9e765b03 100644 --- a/packages/discord.js/src/structures/Webhook.js +++ b/packages/discord.js/src/structures/Webhook.js @@ -367,12 +367,8 @@ class Webhook { * @param {string} [reason] Reason for deleting this webhook * @returns {Promise} */ - async delete(reason) { - // This doesn't call `Client`'s `deleteWebhook` method because `WebhookClient` lacks it, see #9785. - 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 }); } /**