From c3c743285aa8b3f873d91f28f358f356a760a29e Mon Sep 17 00:00:00 2001 From: Jaw0r3k Date: Thu, 17 Aug 2023 18:12:05 +0200 Subject: [PATCH] feat(Client): add deleteWebhook method (#9777) * feat(Client): deleteWebhook method * Update packages/discord.js/src/client/Client.js Co-authored-by: Jiralite <33201955+Jiralite@users.noreply.github.com> * chore: suggested changes Co-authored-by: Jiralite <33201955+Jiralite@users.noreply.github.com> --------- Co-authored-by: Jiralite <33201955+Jiralite@users.noreply.github.com> Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com> --- packages/discord.js/src/client/Client.js | 17 +++++++++++++++++ packages/discord.js/src/structures/Webhook.js | 7 ++----- packages/discord.js/typings/index.d.ts | 6 ++++++ 3 files changed, 25 insertions(+), 5 deletions(-) diff --git a/packages/discord.js/src/client/Client.js b/packages/discord.js/src/client/Client.js index 07d15c973f6d4..80719e864786e 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 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 64f258614a755..738d9e765b030 100644 --- a/packages/discord.js/src/structures/Webhook.js +++ b/packages/discord.js/src/structures/Webhook.js @@ -367,11 +367,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 }); } /** diff --git a/packages/discord.js/typings/index.d.ts b/packages/discord.js/typings/index.d.ts index 78503e17ebe35..fda9b4c0860df 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; @@ -6403,6 +6404,11 @@ export interface WebhookClientDataURL { export type WebhookClientOptions = Pick; +export interface WebhookDeleteOptions { + token?: string; + reason?: string; +} + export interface WebhookEditOptions { name?: string; avatar?: BufferResolvable | null;