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>
This commit is contained in:
Jaw0r3k 2023-08-17 18:12:05 +02:00 committed by GitHub
parent 24fbb11ba2
commit d90ba8dce8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 25 additions and 5 deletions

View file

@ -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

View file

@ -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 });
}
/**

View file

@ -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>;
@ -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;