mirror of
https://github.com/danbulant/discord.js
synced 2026-05-27 22:11:53 +00:00
feat(GuildEmoji): cache the author (#4334)
Co-authored-by: Papaia <43409674+Papaia@users.noreply.github.com>
This commit is contained in:
parent
599cde3627
commit
b7740d4859
2 changed files with 23 additions and 10 deletions
|
|
@ -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;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
1
typings/index.d.ts
vendored
1
typings/index.d.ts
vendored
|
|
@ -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<GuildEmoji>;
|
||||
|
|
|
|||
Loading…
Reference in a new issue