mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-10 16:43:31 +01:00
feat(GuildEmoji): cache the author (#4334)
Co-authored-by: Papaia <43409674+Papaia@users.noreply.github.com>
This commit is contained in:
@@ -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<User>}
|
||||
*/
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user