From 8f846ba2f5e4412e9fb163af3bc9093502c383bd Mon Sep 17 00:00:00 2001 From: StockerMC <44980366+StockerMC@users.noreply.github.com> Date: Fri, 15 Oct 2021 13:32:55 -0400 Subject: [PATCH] Add the ability to set the option name with commands.Option --- discord/ext/commands/converter.py | 6 ++++-- discord/ext/commands/core.py | 6 +++++- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/discord/ext/commands/converter.py b/discord/ext/commands/converter.py index feff650d..0e9a3daf 100644 --- a/discord/ext/commands/converter.py +++ b/discord/ext/commands/converter.py @@ -1039,16 +1039,18 @@ class Option(Generic[T, DT]): # type: ignore __slots__ = ( "default", "description", + "name", ) - def __init__(self, default: T = inspect.Parameter.empty, *, description: DT) -> None: + def __init__(self, default: T = inspect.Parameter.empty, *, description: DT, name: str = discord.utils.MISSING) -> None: self.description = description self.default = default + self.name: str = name if TYPE_CHECKING: # Terrible workaround for type checking reasons - def Option(default: T = inspect.Parameter.empty, *, description: str) -> T: + def Option(default: T = inspect.Parameter.empty, *, description: str, name: str = discord.utils.MISSING) -> T: ... diff --git a/discord/ext/commands/core.py b/discord/ext/commands/core.py index 42ef5ff9..a23ae878 100644 --- a/discord/ext/commands/core.py +++ b/discord/ext/commands/core.py @@ -174,8 +174,12 @@ def get_signature_parameters( annotation = parameter.annotation if isinstance(parameter.default, Option): # type: ignore option = parameter.default - descriptions[name] = option.description parameter = parameter.replace(default=option.default) + if option.name is not MISSING: + name = option.name + parameter.replace(name=name) + + descriptions[name] = option.description if annotation is parameter.empty: params[name] = parameter