mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-15 02:53:31 +01:00
feat(GuildEmojiManager): implement GuildEmojiManager#fetch (#4933)
* feat: GuildEmojiManager#fetch * typings: GuildEmojiManager#fetch
This commit is contained in:
@@ -66,6 +66,39 @@ class GuildEmojiManager extends BaseGuildEmojiManager {
|
|||||||
.emojis.post({ data, reason })
|
.emojis.post({ data, reason })
|
||||||
.then(emoji => this.client.actions.GuildEmojiCreate.handle(this.guild, emoji).emoji);
|
.then(emoji => this.client.actions.GuildEmojiCreate.handle(this.guild, emoji).emoji);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Obtains one or more emojis from Discord, or the emoji cache if they're already available.
|
||||||
|
* @param {Snowflake} [id] ID of the emoji
|
||||||
|
* @param {boolean} [cache=true] Whether to cache the new emoji objects if it weren't already
|
||||||
|
* @param {boolean} [force=false] Whether to skip the cache check and request the API
|
||||||
|
* @returns {Promise<GuildEmoji|Collection<Snowflake, GuildEmoji>>}
|
||||||
|
* @example
|
||||||
|
* // Fetch all emojis from the guild
|
||||||
|
* message.guild.emojis.fetch()
|
||||||
|
* .then(emojis => console.log(`There are ${emojis.size} emojis.`))
|
||||||
|
* .catch(console.error);
|
||||||
|
* @example
|
||||||
|
* // Fetch a single emoji
|
||||||
|
* message.guild.emojis.fetch('222078108977594368')
|
||||||
|
* .then(emoji => console.log(`The emoji name is: ${emoji.name}`))
|
||||||
|
* .catch(console.error);
|
||||||
|
*/
|
||||||
|
async fetch(id, cache = true, force = false) {
|
||||||
|
if (id) {
|
||||||
|
if (!force) {
|
||||||
|
const existing = this.cache.get(id);
|
||||||
|
if (existing) return existing;
|
||||||
|
}
|
||||||
|
const emoji = await this.client.api.guilds(this.guild.id).emojis(id).get();
|
||||||
|
return this.add(emoji, cache);
|
||||||
|
}
|
||||||
|
|
||||||
|
const data = await this.client.api.guilds(this.guild.id).emojis.get();
|
||||||
|
const emojis = new Collection();
|
||||||
|
for (const emoji of data) emojis.set(emoji.id, this.add(emoji, cache));
|
||||||
|
return emojis;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = GuildEmojiManager;
|
module.exports = GuildEmojiManager;
|
||||||
|
|||||||
2
typings/index.d.ts
vendored
2
typings/index.d.ts
vendored
@@ -1913,6 +1913,8 @@ declare module 'discord.js' {
|
|||||||
name: string,
|
name: string,
|
||||||
options?: GuildEmojiCreateOptions,
|
options?: GuildEmojiCreateOptions,
|
||||||
): Promise<GuildEmoji>;
|
): Promise<GuildEmoji>;
|
||||||
|
public fetch(id: Snowflake, cache?: boolean, force?: boolean): Promise<GuildEmoji>;
|
||||||
|
public fetch(id?: Snowflake, cache?: boolean, force?: boolean): Promise<Collection<Snowflake, GuildEmoji>>;
|
||||||
}
|
}
|
||||||
|
|
||||||
export class GuildEmojiRoleManager {
|
export class GuildEmojiRoleManager {
|
||||||
|
|||||||
Reference in New Issue
Block a user