diff --git a/packages/discord.js/src/structures/Webhook.js b/packages/discord.js/src/structures/Webhook.js index 0632c1c72..bdd4df41f 100644 --- a/packages/discord.js/src/structures/Webhook.js +++ b/packages/discord.js/src/structures/Webhook.js @@ -85,6 +85,16 @@ class Webhook { this.owner ??= null; } + if ('application_id' in data) { + /** + * The application that created this webhook + * @type {?Snowflake} + */ + this.applicationId = data.application_id; + } else { + this.applicationId ??= null; + } + if ('source_guild' in data) { /** * The source guild of the webhook @@ -393,6 +403,22 @@ class Webhook { return this.avatar && this.client.rest.cdn.Avatar(this.id, this.avatar, options); } + /** + * Whether this webhook is created by a user. + * @returns {boolean} + */ + isUserCreated() { + return Boolean(this.type === WebhookType.Incoming && this.owner && !this.owner.bot); + } + + /** + * Whether this webhook is created by an application. + * @returns {boolean} + */ + isApplicationCreated() { + return this.type === WebhookType.Application; + } + /** * Whether or not this webhook is a channel follower webhook. * @returns {boolean} diff --git a/packages/discord.js/typings/index.d.ts b/packages/discord.js/typings/index.d.ts index 49bada92e..6237f9fd2 100644 --- a/packages/discord.js/typings/index.d.ts +++ b/packages/discord.js/typings/index.d.ts @@ -2417,10 +2417,28 @@ export class Webhook extends WebhookMixin() { public sourceChannel: NewsChannel | APIPartialChannel | null; public token: string | null; public type: WebhookType; - public isIncoming(): this is this & { token: string }; + public applicationId: Snowflake | null; + public isUserCreated(): this is this & { + type: WebhookType.Incoming; + applicationId: null; + owner: User | APIUser; + }; + public isApplicationCreated(): this is this & { + type: WebhookType.Application; + applicationId: Snowflake; + owner: User | APIUser; + }; + public isIncoming(): this is this & { + type: WebhookType.Incoming; + token: string; + }; public isChannelFollower(): this is this & { + type: WebhookType.ChannelFollower; sourceGuild: Guild | APIPartialGuild; sourceChannel: NewsChannel | APIPartialChannel; + token: null; + applicationId: null; + owner: User | APIUser; }; }