From 116ecf246e89db4d629a13877a440260c7504e30 Mon Sep 17 00:00:00 2001 From: Souji Date: Fri, 30 Apr 2021 21:44:23 +0200 Subject: [PATCH] feat(Webhook): sourceGuild, sourceChannel, improve owner (#5508) --- src/structures/Webhook.js | 28 +++++++++++++++++++--------- typings/index.d.ts | 2 ++ 2 files changed, 21 insertions(+), 9 deletions(-) diff --git a/src/structures/Webhook.js b/src/structures/Webhook.js index 6b8d2ca94..e8a3b1bea 100644 --- a/src/structures/Webhook.js +++ b/src/structures/Webhook.js @@ -65,15 +65,25 @@ class Webhook { */ this.channelID = data.channel_id; - if (data.user) { - /** - * The owner of the webhook - * @type {?User|Object} - */ - this.owner = this.client.users ? this.client.users.cache.get(data.user.id) : data.user; - } else { - this.owner = null; - } + /** + * The owner of the webhook + * @type {?User|Object} + */ + this.owner = data.user ? this.client.users?.add(data.user) ?? data.user : null; + + /** + * The source guild of the webhook + * @type {?Guild|Object} + */ + this.sourceGuild = data.source_guild + ? this.client.guilds?.add(data.source_guild, false) ?? data.source_guild + : null; + + /** + * The source channel of the webhook + * @type {?Channel|Object} + */ + this.sourceChannel = this.client.channels?.resolve(data.source_channel?.id) ?? data.source_channel ?? null; } /** diff --git a/typings/index.d.ts b/typings/index.d.ts index 84b249657..418282217 100644 --- a/typings/index.d.ts +++ b/typings/index.d.ts @@ -1800,6 +1800,8 @@ declare module 'discord.js' { public guildID: Snowflake; public name: string; public owner: User | object | null; + public sourceGuild: Guild | object | null; + public sourceChannel: Channel | object | null; public token: string | null; public type: WebhookTypes; }