Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(Client): add deleteWebhook method #9777

Merged
merged 4 commits into from
Aug 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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