mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-13 01:53:30 +01:00
feat: Add ApplicationEmoji to EmojiResolvable and MessageReaction#emoji (#10477)
* types: add ApplicationEmoji to EmojiResolvable * typings: add ApplicationEmoji to MessageReaction#emoji * removed ApplicationEmoji from MessageReaction * update BaseGuildEmojiManager * chore: lint error * feat: add ApplicationEmoji to MessageReaction#emoji getter * refactor: check application emojis first --------- Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
const CachedManager = require('./CachedManager');
|
const CachedManager = require('./CachedManager');
|
||||||
|
const ApplicationEmoji = require('../structures/ApplicationEmoji');
|
||||||
const GuildEmoji = require('../structures/GuildEmoji');
|
const GuildEmoji = require('../structures/GuildEmoji');
|
||||||
const ReactionEmoji = require('../structures/ReactionEmoji');
|
const ReactionEmoji = require('../structures/ReactionEmoji');
|
||||||
const { parseEmoji } = require('../util/Util');
|
const { parseEmoji } = require('../util/Util');
|
||||||
@@ -25,7 +26,8 @@ class BaseGuildEmojiManager extends CachedManager {
|
|||||||
* * A Snowflake
|
* * A Snowflake
|
||||||
* * A GuildEmoji object
|
* * A GuildEmoji object
|
||||||
* * A ReactionEmoji object
|
* * A ReactionEmoji object
|
||||||
* @typedef {Snowflake|GuildEmoji|ReactionEmoji} EmojiResolvable
|
* * An ApplicationEmoji object
|
||||||
|
* @typedef {Snowflake|GuildEmoji|ReactionEmoji|ApplicationEmoji} EmojiResolvable
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -35,6 +37,7 @@ class BaseGuildEmojiManager extends CachedManager {
|
|||||||
*/
|
*/
|
||||||
resolve(emoji) {
|
resolve(emoji) {
|
||||||
if (emoji instanceof ReactionEmoji) return super.resolve(emoji.id);
|
if (emoji instanceof ReactionEmoji) return super.resolve(emoji.id);
|
||||||
|
if (emoji instanceof ApplicationEmoji) return super.resolve(emoji.id);
|
||||||
return super.resolve(emoji);
|
return super.resolve(emoji);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -45,6 +48,7 @@ class BaseGuildEmojiManager extends CachedManager {
|
|||||||
*/
|
*/
|
||||||
resolveId(emoji) {
|
resolveId(emoji) {
|
||||||
if (emoji instanceof ReactionEmoji) return emoji.id;
|
if (emoji instanceof ReactionEmoji) return emoji.id;
|
||||||
|
if (emoji instanceof ApplicationEmoji) return emoji.id;
|
||||||
return super.resolveId(emoji);
|
return super.resolveId(emoji);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -65,6 +69,7 @@ class BaseGuildEmojiManager extends CachedManager {
|
|||||||
const emojiResolvable = this.resolve(emoji);
|
const emojiResolvable = this.resolve(emoji);
|
||||||
if (emojiResolvable) return emojiResolvable.identifier;
|
if (emojiResolvable) return emojiResolvable.identifier;
|
||||||
if (emoji instanceof ReactionEmoji) return emoji.identifier;
|
if (emoji instanceof ReactionEmoji) return emoji.identifier;
|
||||||
|
if (emoji instanceof ApplicationEmoji) return emoji.identifier;
|
||||||
if (typeof emoji === 'string') {
|
if (typeof emoji === 'string') {
|
||||||
const res = parseEmoji(emoji);
|
const res = parseEmoji(emoji);
|
||||||
if (res?.name.length) {
|
if (res?.name.length) {
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
const { Routes } = require('discord-api-types/v10');
|
const { Routes } = require('discord-api-types/v10');
|
||||||
|
const ApplicationEmoji = require('./ApplicationEmoji');
|
||||||
const GuildEmoji = require('./GuildEmoji');
|
const GuildEmoji = require('./GuildEmoji');
|
||||||
const ReactionEmoji = require('./ReactionEmoji');
|
const ReactionEmoji = require('./ReactionEmoji');
|
||||||
const ReactionUserManager = require('../managers/ReactionUserManager');
|
const ReactionUserManager = require('../managers/ReactionUserManager');
|
||||||
@@ -108,16 +109,24 @@ class MessageReaction {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The emoji of this reaction. Either a {@link GuildEmoji} object for known custom emojis, or a {@link ReactionEmoji}
|
* The emoji of this reaction. Either a {@link GuildEmoji} object for known custom emojis,
|
||||||
* object which has fewer properties. Whatever the prototype of the emoji, it will still have
|
* {@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()`
|
* `name`, `id`, `identifier` and `toString()`
|
||||||
* @type {GuildEmoji|ReactionEmoji}
|
* @type {GuildEmoji|ReactionEmoji|ApplicationEmoji}
|
||||||
* @readonly
|
* @readonly
|
||||||
*/
|
*/
|
||||||
get emoji() {
|
get emoji() {
|
||||||
if (this._emoji instanceof GuildEmoji) return this._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
|
// Check to see if the emoji has become known to the client
|
||||||
if (this._emoji.id) {
|
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;
|
const emojis = this.message.client.emojis.cache;
|
||||||
if (emojis.has(this._emoji.id)) {
|
if (emojis.has(this._emoji.id)) {
|
||||||
const emoji = emojis.get(this._emoji.id);
|
const emoji = emojis.get(this._emoji.id);
|
||||||
|
|||||||
6
packages/discord.js/typings/index.d.ts
vendored
6
packages/discord.js/typings/index.d.ts
vendored
@@ -2462,13 +2462,13 @@ export class MessagePayload {
|
|||||||
|
|
||||||
export class MessageReaction {
|
export class MessageReaction {
|
||||||
private constructor(client: Client<true>, data: RawMessageReactionData, message: Message);
|
private constructor(client: Client<true>, data: RawMessageReactionData, message: Message);
|
||||||
private _emoji: GuildEmoji | ReactionEmoji;
|
private _emoji: GuildEmoji | ReactionEmoji | ApplicationEmoji;
|
||||||
|
|
||||||
public burstColors: string[] | null;
|
public burstColors: string[] | null;
|
||||||
public readonly client: Client<true>;
|
public readonly client: Client<true>;
|
||||||
public count: number;
|
public count: number;
|
||||||
public countDetails: ReactionCountDetailsData;
|
public countDetails: ReactionCountDetailsData;
|
||||||
public get emoji(): GuildEmoji | ReactionEmoji;
|
public get emoji(): GuildEmoji | ReactionEmoji | ApplicationEmoji;
|
||||||
public me: boolean;
|
public me: boolean;
|
||||||
public meBurst: boolean;
|
public meBurst: boolean;
|
||||||
public message: Message | PartialMessage;
|
public message: Message | PartialMessage;
|
||||||
@@ -5709,7 +5709,7 @@ export type EmojiIdentifierResolvable =
|
|||||||
| `<${'' | 'a'}:${string}:${Snowflake}>`
|
| `<${'' | 'a'}:${string}:${Snowflake}>`
|
||||||
| string;
|
| string;
|
||||||
|
|
||||||
export type EmojiResolvable = Snowflake | GuildEmoji | ReactionEmoji;
|
export type EmojiResolvable = Snowflake | GuildEmoji | ReactionEmoji | ApplicationEmoji;
|
||||||
|
|
||||||
export interface FetchApplicationCommandOptions extends BaseFetchOptions {
|
export interface FetchApplicationCommandOptions extends BaseFetchOptions {
|
||||||
guildId?: Snowflake;
|
guildId?: Snowflake;
|
||||||
|
|||||||
Reference in New Issue
Block a user