Skip to content

Commit 3143637

Browse files
authored
feat: allow usage of unicode emoji in PartialEmojiConverter (#2819)
* Update converter.py * fix: enhance PartialEmojiConverter to support direct emoji names * update doc
1 parent ce07e86 commit 3143637

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

discord/ext/commands/converter.py

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
)
4242

4343
import discord
44+
from discord.partial_emoji import EMOJIS_MAP
4445

4546
from .errors import *
4647

@@ -851,7 +852,8 @@ async def convert(self, ctx: Context, argument: str) -> discord.GuildEmoji:
851852
class PartialEmojiConverter(Converter[discord.PartialEmoji]):
852853
"""Converts to a :class:`~discord.PartialEmoji`.
853854
854-
This is done by extracting the animated flag, name and ID from the emoji.
855+
This is done by extracting the animated flag, name, and ID for custom emojis,
856+
or by using the standard Unicode emojis supported by Discord.
855857
856858
.. versionchanged:: 1.5
857859
Raise :exc:`.PartialEmojiConversionFailure` instead of generic :exc:`.BadArgument`
@@ -872,6 +874,14 @@ async def convert(self, ctx: Context, argument: str) -> discord.PartialEmoji:
872874
id=emoji_id,
873875
)
874876

877+
if argument in EMOJIS_MAP.values():
878+
return discord.PartialEmoji.with_state(
879+
ctx.bot._connection,
880+
animated=False,
881+
name=argument,
882+
id=None,
883+
)
884+
875885
raise PartialEmojiConversionFailure(argument)
876886

877887

@@ -1094,7 +1104,11 @@ def get_converter(param: inspect.Parameter) -> Any:
10941104

10951105

10961106
def is_generic_type(tp: Any, *, _GenericAlias: type = _GenericAlias) -> bool:
1097-
return isinstance(tp, type) and issubclass(tp, Generic) or isinstance(tp, _GenericAlias) # type: ignore
1107+
return (
1108+
isinstance(tp, type)
1109+
and issubclass(tp, Generic)
1110+
or isinstance(tp, _GenericAlias)
1111+
) # type: ignore
10981112

10991113

11001114
CONVERTER_MAPPING: dict[type[Any], Any] = {

0 commit comments

Comments
 (0)