Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add ApplicationEmoji to EmojiResolvable and MessageReaction#emoji #10477

Merged
merged 9 commits into from
Oct 1, 2024
7 changes: 6 additions & 1 deletion packages/discord.js/src/managers/BaseGuildEmojiManager.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
'use strict';

const CachedManager = require('./CachedManager');
const ApplicationEmoji = require('../structures/ApplicationEmoji');
const GuildEmoji = require('../structures/GuildEmoji');
const ReactionEmoji = require('../structures/ReactionEmoji');
const { parseEmoji } = require('../util/Util');
Expand All @@ -25,7 +26,8 @@ class BaseGuildEmojiManager extends CachedManager {
* * A Snowflake
* * A GuildEmoji object
* * A ReactionEmoji object
* @typedef {Snowflake|GuildEmoji|ReactionEmoji} EmojiResolvable
* * An ApplicationEmoji object
* @typedef {Snowflake|GuildEmoji|ReactionEmoji|ApplicationEmoji} EmojiResolvable
*/

/**
Expand All @@ -35,6 +37,7 @@ class BaseGuildEmojiManager extends CachedManager {
*/
resolve(emoji) {
if (emoji instanceof ReactionEmoji) return super.resolve(emoji.id);
if (emoji instanceof ApplicationEmoji) return super.resolve(emoji.id);
return super.resolve(emoji);
}

Expand All @@ -45,6 +48,7 @@ class BaseGuildEmojiManager extends CachedManager {
*/
resolveId(emoji) {
if (emoji instanceof ReactionEmoji) return emoji.id;
if (emoji instanceof ApplicationEmoji) return emoji.id;
return super.resolveId(emoji);
}

Expand All @@ -65,6 +69,7 @@ class BaseGuildEmojiManager extends CachedManager {
const emojiResolvable = this.resolve(emoji);
if (emojiResolvable) return emojiResolvable.identifier;
if (emoji instanceof ReactionEmoji) return emoji.identifier;
if (emoji instanceof ApplicationEmoji) return emoji.identifier;
if (typeof emoji === 'string') {
const res = parseEmoji(emoji);
if (res?.name.length) {
Expand Down
15 changes: 12 additions & 3 deletions packages/discord.js/src/structures/MessageReaction.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
'use strict';

const { Routes } = require('discord-api-types/v10');
const ApplicationEmoji = require('./ApplicationEmoji');
const GuildEmoji = require('./GuildEmoji');
const ReactionEmoji = require('./ReactionEmoji');
const ReactionUserManager = require('../managers/ReactionUserManager');
Expand Down Expand Up @@ -108,16 +109,24 @@ class MessageReaction {
}

/**
* The emoji of this reaction. Either a {@link GuildEmoji} object for known custom emojis, or a {@link ReactionEmoji}
* object which has fewer properties. Whatever the prototype of the emoji, it will still have
* The emoji of this reaction. Either a {@link GuildEmoji} object for known custom emojis,
* {@link ApplicationEmoji} for application emojis, or a {@link ReactionEmoji} object
* which has fewer properties. Whatever the prototype of the emoji, it will still have
* `name`, `id`, `identifier` and `toString()`
* @type {GuildEmoji|ReactionEmoji}
* @type {GuildEmoji|ReactionEmoji|ApplicationEmoji}
* @readonly
*/
get emoji() {
if (this._emoji instanceof GuildEmoji) return this._emoji;
if (this._emoji instanceof ApplicationEmoji) return this._emoji;
// Check to see if the emoji has become known to the client
if (this._emoji.id) {
const applicationEmojis = this.message.client.application.emojis.cache;
if (applicationEmojis.has(this._emoji.id)) {
const emoji = applicationEmojis.get(this._emoji.id);
this._emoji = emoji;
return emoji;
}
const emojis = this.message.client.emojis.cache;
if (emojis.has(this._emoji.id)) {
const emoji = emojis.get(this._emoji.id);
Expand Down
6 changes: 3 additions & 3 deletions packages/discord.js/typings/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2430,13 +2430,13 @@ export class MessagePayload {

export class MessageReaction {
private constructor(client: Client<true>, data: RawMessageReactionData, message: Message);
private _emoji: GuildEmoji | ReactionEmoji;
private _emoji: GuildEmoji | ReactionEmoji | ApplicationEmoji;

public burstColors: string[] | null;
public readonly client: Client<true>;
public count: number;
public countDetails: ReactionCountDetailsData;
public get emoji(): GuildEmoji | ReactionEmoji;
public get emoji(): GuildEmoji | ReactionEmoji | ApplicationEmoji;
didinele marked this conversation as resolved.
Show resolved Hide resolved
public me: boolean;
public meBurst: boolean;
public message: Message | PartialMessage;
Expand Down Expand Up @@ -5677,7 +5677,7 @@ export type EmojiIdentifierResolvable =
| `<${'' | 'a'}:${string}:${Snowflake}>`
| string;

export type EmojiResolvable = Snowflake | GuildEmoji | ReactionEmoji;
export type EmojiResolvable = Snowflake | GuildEmoji | ReactionEmoji | ApplicationEmoji;

export interface FetchApplicationCommandOptions extends BaseFetchOptions {
guildId?: Snowflake;
Expand Down