diff --git a/packages/discord.js/src/client/Client.js b/packages/discord.js/src/client/Client.js index 07d15c973f6d..80719e864786 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 64f258614a75..738d9e765b03 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 78503e17ebe3..fda9b4c0860d 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;