mirror of
https://github.com/Rapptz/discord.py.git
synced 2025-08-31 07:21:41 +00:00
[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.
This commit is contained in:
parent
63e50bc369
commit
6d55b96fa7
@ -44,7 +44,7 @@ from discord import app_commands
|
|||||||
from discord.utils import MISSING, maybe_coroutine, async_all
|
from discord.utils import MISSING, maybe_coroutine, async_all
|
||||||
from .core import Command, Group
|
from .core import Command, Group
|
||||||
from .errors import BadArgument, CommandRegistrationError, CommandError, HybridCommandError, ConversionError
|
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 .parameters import Parameter
|
||||||
from .flags import is_flag, FlagConverter
|
from .flags import is_flag, FlagConverter
|
||||||
from .cog import Cog
|
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]:
|
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:
|
async def transform(cls, interaction: discord.Interaction, value: str) -> Any:
|
||||||
try:
|
try:
|
||||||
if inspect.isclass(converter) and issubclass(converter, Converter):
|
if inspect.isclass(converter) and issubclass(converter, Converter):
|
||||||
@ -219,7 +227,7 @@ def replace_parameter(
|
|||||||
if renames:
|
if renames:
|
||||||
app_commands.rename(**renames)(callback)
|
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))
|
param = param.replace(annotation=make_converter_transformer(converter))
|
||||||
elif origin is Union:
|
elif origin is Union:
|
||||||
if len(args) == 2 and args[-1] is _NoneType:
|
if len(args) == 2 and args[-1] is _NoneType:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user