feat(Webhook): sourceGuild, sourceChannel, improve owner (#5508)

This commit is contained in:
Souji
2021-04-30 21:44:23 +02:00
committed by GitHub
parent 9572521e3c
commit 116ecf246e
2 changed files with 21 additions and 9 deletions

View File

@@ -65,15 +65,25 @@ class Webhook {
*/ */
this.channelID = data.channel_id; this.channelID = data.channel_id;
if (data.user) { /**
/** * The owner of the webhook
* The owner of the webhook * @type {?User|Object}
* @type {?User|Object} */
*/ this.owner = data.user ? this.client.users?.add(data.user) ?? data.user : null;
this.owner = this.client.users ? this.client.users.cache.get(data.user.id) : data.user;
} else { /**
this.owner = 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;
} }
/** /**

2
typings/index.d.ts vendored
View File

@@ -1800,6 +1800,8 @@ declare module 'discord.js' {
public guildID: Snowflake; public guildID: Snowflake;
public name: string; public name: string;
public owner: User | object | null; public owner: User | object | null;
public sourceGuild: Guild | object | null;
public sourceChannel: Channel | object | null;
public token: string | null; public token: string | null;
public type: WebhookTypes; public type: WebhookTypes;
} }