From 6d55b96fa7915d0e3b91db2cf8300a3746911114 Mon Sep 17 00:00:00 2001 From: Rapptz Date: Wed, 11 May 2022 19:29:06 -0400 Subject: [PATCH] [commands] Fix unsupported discord converters in hybrid commands These are things that are supported in regular commands but not in application commands, such as discord.Colour, discord.Game, or discord.Emoji. --- discord/ext/commands/hybrid.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/discord/ext/commands/hybrid.py b/discord/ext/commands/hybrid.py index 0db651a20..282a88451 100644 --- a/discord/ext/commands/hybrid.py +++ b/discord/ext/commands/hybrid.py @@ -44,7 +44,7 @@ from discord import app_commands from discord.utils import MISSING, maybe_coroutine, async_all from .core import Command, Group from .errors import BadArgument, CommandRegistrationError, CommandError, HybridCommandError, ConversionError -from .converter import Converter, Range, Greedy, run_converters +from .converter import Converter, Range, Greedy, run_converters, CONVERTER_MAPPING from .parameters import Parameter from .flags import is_flag, FlagConverter from .cog import Cog @@ -117,6 +117,14 @@ def required_pos_arguments(func: Callable[..., Any]) -> int: def make_converter_transformer(converter: Any) -> Type[app_commands.Transformer]: + try: + module = converter.__module__ + except AttributeError: + pass + else: + if module is not None and (module.startswith('discord.') and not module.endswith('converter')): + converter = CONVERTER_MAPPING.get(converter, converter) + async def transform(cls, interaction: discord.Interaction, value: str) -> Any: try: if inspect.isclass(converter) and issubclass(converter, Converter): @@ -219,7 +227,7 @@ def replace_parameter( if renames: app_commands.rename(**renames)(callback) - elif is_converter(converter): + elif is_converter(converter) or converter in CONVERTER_MAPPING: param = param.replace(annotation=make_converter_transformer(converter)) elif origin is Union: if len(args) == 2 and args[-1] is _NoneType: