From 0cb79e13581453a94e5b1b46850f2e8985574d2e Mon Sep 17 00:00:00 2001 From: Soheab_ <33902984+Soheab@users.noreply.github.com> Date: Sun, 28 Jul 2024 15:42:30 +0200 Subject: [PATCH] Support commands.parameter for hybrid app commands --- discord/ext/commands/hybrid.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/discord/ext/commands/hybrid.py b/discord/ext/commands/hybrid.py index 8c2f9a9e9..4ed42ad75 100644 --- a/discord/ext/commands/hybrid.py +++ b/discord/ext/commands/hybrid.py @@ -271,7 +271,11 @@ def replace_parameters( ) -> List[inspect.Parameter]: # Need to convert commands.Parameter back to inspect.Parameter so this will be a bit ugly params = signature.parameters.copy() + + pending_rename: Dict[str, str] = {} + pending_description: Dict[str, str] = {} for name, parameter in parameters.items(): + converter = parameter.converter # Parameter.converter properly infers from the default and has a str default # This allows the actual signature to inherit this property @@ -282,6 +286,12 @@ def replace_parameters( default = _CallableDefault(parameter.default) if callable(parameter.default) else parameter.default param = param.replace(default=default) + if parameter.description: + pending_description[name] = parameter.description + + if parameter.displayed_name: + pending_rename[name] = parameter.displayed_name + if isinstance(param.default, Parameter): # If we're here, then then it hasn't been handled yet so it should be removed completely param = param.replace(default=parameter.empty) @@ -293,6 +303,12 @@ def replace_parameters( params[name] = param + if pending_description: + app_commands.describe(**pending_description)(callback) + + if pending_rename: + app_commands.rename(**pending_rename)(callback) + return list(params.values())