diff --git a/src/structures/GuildEmoji.js b/src/structures/GuildEmoji.js index d4189e9f2..4e9035046 100644 --- a/src/structures/GuildEmoji.js +++ b/src/structures/GuildEmoji.js @@ -11,13 +11,19 @@ const Permissions = require('../util/Permissions'); */ class GuildEmoji extends BaseGuildEmoji { /** - * @name GuildEmoji - * @kind constructor - * @memberof GuildEmoji * @param {Client} client The instantiating client * @param {Object} data The data for the guild emoji * @param {Guild} guild The guild the guild emoji is part of */ + constructor(client, data, guild) { + super(client, data, guild); + + /** + * The user who created this emoji + * @type {?User} + */ + this.author = null; + } /** * The guild this emoji is part of @@ -31,6 +37,11 @@ class GuildEmoji extends BaseGuildEmoji { return clone; } + _patch(data) { + super._patch(data); + if (typeof data.user !== 'undefined') this.author = this.client.users.add(data.user); + } + /** * Whether the emoji is deletable by the client user * @type {boolean} @@ -54,20 +65,21 @@ class GuildEmoji extends BaseGuildEmoji { * Fetches the author for this emoji * @returns {Promise} */ - fetchAuthor() { + async fetchAuthor() { if (this.managed) { - return Promise.reject(new Error('EMOJI_MANAGED')); + throw new Error('EMOJI_MANAGED'); } else { - if (!this.guild.me) return Promise.reject(new Error('GUILD_UNCACHED_ME')); + if (!this.guild.me) throw new Error('GUILD_UNCACHED_ME'); if (!this.guild.me.permissions.has(Permissions.FLAGS.MANAGE_EMOJIS)) { - return Promise.reject(new Error('MISSING_MANAGE_EMOJIS_PERMISSION', this.guild)); + throw new Error('MISSING_MANAGE_EMOJIS_PERMISSION', this.guild); } } - return this.client.api + const data = await this.client.api .guilds(this.guild.id) .emojis(this.id) - .get() - .then(emoji => this.client.users.add(emoji.user)); + .get(); + this._patch(data); + return this.author; } /** diff --git a/typings/index.d.ts b/typings/index.d.ts index 8209f3a38..340b2043b 100644 --- a/typings/index.d.ts +++ b/typings/index.d.ts @@ -793,6 +793,7 @@ declare module 'discord.js' { export class GuildEmoji extends BaseGuildEmoji { public readonly deletable: boolean; public guild: Guild; + public author: User | null; public readonly roles: GuildEmojiRoleManager; public readonly url: string; public delete(reason?: string): Promise;