mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-16 19:43:29 +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 {
|
class GuildEmoji extends BaseGuildEmoji {
|
||||||
/**
|
/**
|
||||||
* @name GuildEmoji
|
|
||||||
* @kind constructor
|
|
||||||
* @memberof GuildEmoji
|
|
||||||
* @param {Client} client The instantiating client
|
* @param {Client} client The instantiating client
|
||||||
* @param {Object} data The data for the guild emoji
|
* @param {Object} data The data for the guild emoji
|
||||||
* @param {Guild} guild The guild the guild emoji is part of
|
* @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
|
* The guild this emoji is part of
|
||||||
@@ -31,6 +37,11 @@ class GuildEmoji extends BaseGuildEmoji {
|
|||||||
return clone;
|
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
|
* Whether the emoji is deletable by the client user
|
||||||
* @type {boolean}
|
* @type {boolean}
|
||||||
@@ -54,20 +65,21 @@ class GuildEmoji extends BaseGuildEmoji {
|
|||||||
* Fetches the author for this emoji
|
* Fetches the author for this emoji
|
||||||
* @returns {Promise<User>}
|
* @returns {Promise<User>}
|
||||||
*/
|
*/
|
||||||
fetchAuthor() {
|
async fetchAuthor() {
|
||||||
if (this.managed) {
|
if (this.managed) {
|
||||||
return Promise.reject(new Error('EMOJI_MANAGED'));
|
throw new Error('EMOJI_MANAGED');
|
||||||
} else {
|
} 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)) {
|
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)
|
.guilds(this.guild.id)
|
||||||
.emojis(this.id)
|
.emojis(this.id)
|
||||||
.get()
|
.get();
|
||||||
.then(emoji => this.client.users.add(emoji.user));
|
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 {
|
export class GuildEmoji extends BaseGuildEmoji {
|
||||||
public readonly deletable: boolean;
|
public readonly deletable: boolean;
|
||||||
public guild: Guild;
|
public guild: Guild;
|
||||||
|
public author: User | null;
|
||||||
public readonly roles: GuildEmojiRoleManager;
|
public readonly roles: GuildEmojiRoleManager;
|
||||||
public readonly url: string;
|
public readonly url: string;
|
||||||
public delete(reason?: string): Promise<GuildEmoji>;
|
public delete(reason?: string): Promise<GuildEmoji>;
|
||||||
|
|||||||
Reference in New Issue
Block a user