Skip to content

Commit

Permalink
feat(Client): add deleteWebhook method (#9777)
Browse files Browse the repository at this point in the history
* feat(Client): deleteWebhook method

* Update packages/discord.js/src/client/Client.js

Co-authored-by: Jiralite <[email protected]>

* chore: suggested changes

Co-authored-by: Jiralite <[email protected]>

---------

Co-authored-by: Jiralite <[email protected]>
Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
  • Loading branch information
3 people authored Aug 17, 2023
1 parent 24fbb11 commit d90ba8d
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 5 deletions.
17 changes: 17 additions & 0 deletions packages/discord.js/src/client/Client.js
Original file line number Diff line number Diff line change
Expand Up @@ -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<void>}
*/
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
Expand Down
7 changes: 2 additions & 5 deletions packages/discord.js/src/structures/Webhook.js
Original file line number Diff line number Diff line change
Expand Up @@ -367,11 +367,8 @@ class Webhook {
* @param {string} [reason] Reason for deleting this webhook
* @returns {Promise<void>}
*/
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 });
}

/**
Expand Down
6 changes: 6 additions & 0 deletions packages/discord.js/typings/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -969,6 +969,7 @@ export class Client<Ready extends boolean = boolean> extends BaseClient {
public voice: ClientVoiceManager;
public ws: WebSocketManager;
public destroy(): Promise<void>;
public deleteWebhook(id: Snowflake, options?: WebhookDeleteOptions): Promise<void>;
public fetchGuildPreview(guild: GuildResolvable): Promise<GuildPreview>;
public fetchInvite(invite: InviteResolvable, options?: ClientFetchInviteOptions): Promise<Invite>;
public fetchGuildTemplate(template: GuildTemplateResolvable): Promise<GuildTemplate>;
Expand Down Expand Up @@ -6403,6 +6404,11 @@ export interface WebhookClientDataURL {

export type WebhookClientOptions = Pick<ClientOptions, 'allowedMentions' | 'rest'>;

export interface WebhookDeleteOptions {
token?: string;
reason?: string;
}

export interface WebhookEditOptions {
name?: string;
avatar?: BufferResolvable | null;
Expand Down

0 comments on commit d90ba8d

Please sign in to comment.