diff --git a/discord/ext/commands/converter.py b/discord/ext/commands/converter.py index 5f75aec6b3..ca5a109f3f 100644 --- a/discord/ext/commands/converter.py +++ b/discord/ext/commands/converter.py @@ -41,7 +41,7 @@ ) import discord -from discord.partial_emoji import EMOJIS_MAP +from discord.utils import UNICODE_EMOJIS from .errors import * @@ -874,7 +874,7 @@ async def convert(self, ctx: Context, argument: str) -> discord.PartialEmoji: id=emoji_id, ) - if argument in EMOJIS_MAP.values(): + if argument in UNICODE_EMOJIS: return discord.PartialEmoji.with_state( ctx.bot._connection, animated=False, diff --git a/discord/partial_emoji.py b/discord/partial_emoji.py index cabe26249f..50e50d311c 100644 --- a/discord/partial_emoji.py +++ b/discord/partial_emoji.py @@ -25,8 +25,6 @@ from __future__ import annotations -import importlib.resources -import json import re from typing import TYPE_CHECKING, Any, TypedDict, TypeVar @@ -34,13 +32,6 @@ from .asset import Asset, AssetMixin from .errors import InvalidArgument -with ( - importlib.resources.files(__package__) - .joinpath("emojis.json") - .open(encoding="utf-8") as f -): - EMOJIS_MAP = json.load(f) - __all__ = ("PartialEmoji",) if TYPE_CHECKING: @@ -152,7 +143,7 @@ def from_str(cls: type[PE], value: str) -> PE: """ if value.startswith(":") and value.endswith(":") and len(value) > 2: name = value[1:-1] - if unicode_emoji := EMOJIS_MAP.get(name): + if unicode_emoji := utils.EMOJIS_MAP.get(name): return cls(name=unicode_emoji, id=None, animated=False) match = cls._CUSTOM_EMOJI_RE.match(value) if match is not None: diff --git a/discord/utils.py b/discord/utils.py index b509162cf0..2f9f94a35a 100644 --- a/discord/utils.py +++ b/discord/utils.py @@ -30,6 +30,7 @@ import collections.abc import datetime import functools +import importlib.resources import itertools import json import re @@ -97,10 +98,21 @@ "generate_snowflake", "basic_autocomplete", "filter_params", + "EMOJIS_MAP", + "UNICODE_EMOJIS", ) DISCORD_EPOCH = 1420070400000 +with ( + importlib.resources.files(__package__) + .joinpath("emojis.json") + .open(encoding="utf-8") as f +): + EMOJIS_MAP = json.load(f) + +UNICODE_EMOJIS = set(EMOJIS_MAP.values()) + class _MissingSentinel: def __eq__(self, other) -> bool: