mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-19 13:03:31 +01:00
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:
@@ -253,6 +253,23 @@ class Client extends BaseClient {
|
|||||||
this.rest.setToken(null);
|
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.
|
* Options used when fetching an invite from Discord.
|
||||||
* @typedef {Object} ClientFetchInviteOptions
|
* @typedef {Object} ClientFetchInviteOptions
|
||||||
|
|||||||
@@ -367,11 +367,8 @@ class Webhook {
|
|||||||
* @param {string} [reason] Reason for deleting this webhook
|
* @param {string} [reason] Reason for deleting this webhook
|
||||||
* @returns {Promise<void>}
|
* @returns {Promise<void>}
|
||||||
*/
|
*/
|
||||||
async delete(reason) {
|
delete(reason) {
|
||||||
await this.client.rest.delete(Routes.webhook(this.id, this.token), {
|
return this.client.deleteWebhook(this.id, { token: this.token, reason });
|
||||||
reason,
|
|
||||||
auth: !this.token,
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
6
packages/discord.js/typings/index.d.ts
vendored
6
packages/discord.js/typings/index.d.ts
vendored
@@ -969,6 +969,7 @@ export class Client<Ready extends boolean = boolean> extends BaseClient {
|
|||||||
public voice: ClientVoiceManager;
|
public voice: ClientVoiceManager;
|
||||||
public ws: WebSocketManager;
|
public ws: WebSocketManager;
|
||||||
public destroy(): Promise<void>;
|
public destroy(): Promise<void>;
|
||||||
|
public deleteWebhook(id: Snowflake, options?: WebhookDeleteOptions): Promise<void>;
|
||||||
public fetchGuildPreview(guild: GuildResolvable): Promise<GuildPreview>;
|
public fetchGuildPreview(guild: GuildResolvable): Promise<GuildPreview>;
|
||||||
public fetchInvite(invite: InviteResolvable, options?: ClientFetchInviteOptions): Promise<Invite>;
|
public fetchInvite(invite: InviteResolvable, options?: ClientFetchInviteOptions): Promise<Invite>;
|
||||||
public fetchGuildTemplate(template: GuildTemplateResolvable): Promise<GuildTemplate>;
|
public fetchGuildTemplate(template: GuildTemplateResolvable): Promise<GuildTemplate>;
|
||||||
@@ -6403,6 +6404,11 @@ export interface WebhookClientDataURL {
|
|||||||
|
|
||||||
export type WebhookClientOptions = Pick<ClientOptions, 'allowedMentions' | 'rest'>;
|
export type WebhookClientOptions = Pick<ClientOptions, 'allowedMentions' | 'rest'>;
|
||||||
|
|
||||||
|
export interface WebhookDeleteOptions {
|
||||||
|
token?: string;
|
||||||
|
reason?: string;
|
||||||
|
}
|
||||||
|
|
||||||
export interface WebhookEditOptions {
|
export interface WebhookEditOptions {
|
||||||
name?: string;
|
name?: string;
|
||||||
avatar?: BufferResolvable | null;
|
avatar?: BufferResolvable | null;
|
||||||
|
|||||||
Reference in New Issue
Block a user