From a938b10e5a680405a99a5d0bb49e8d075fb0fecf Mon Sep 17 00:00:00 2001 From: Soheab_ <33902984+Soheab@users.noreply.github.com> Date: Fri, 3 Mar 2023 15:07:22 +0100 Subject: [PATCH] [commands] Pass failed argument's value to BadLiteralArgument --- discord/ext/commands/converter.py | 2 +- discord/ext/commands/errors.py | 7 ++++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/discord/ext/commands/converter.py b/discord/ext/commands/converter.py index cc7a3eb9b..e5be9d47f 100644 --- a/discord/ext/commands/converter.py +++ b/discord/ext/commands/converter.py @@ -1330,7 +1330,7 @@ async def run_converters(ctx: Context[BotT], converter: Any, argument: str, para return value # if we're here, then we failed to match all the literals - raise BadLiteralArgument(param, literal_args, errors) + raise BadLiteralArgument(param, literal_args, errors, argument) # This must be the last if-clause in the chain of origin checking # Nearly every type is a generic type within the typing library diff --git a/discord/ext/commands/errors.py b/discord/ext/commands/errors.py index 17dd49830..b25e6ae95 100644 --- a/discord/ext/commands/errors.py +++ b/discord/ext/commands/errors.py @@ -920,12 +920,17 @@ class BadLiteralArgument(UserInputError): A tuple of values compared against in conversion, in order of failure. errors: List[:class:`CommandError`] A list of errors that were caught from failing the conversion. + argument: :class:`str` + The argument's value that failed to be converted. Defaults to an empty string. + + .. versionadded:: 2.3 """ - def __init__(self, param: Parameter, literals: Tuple[Any, ...], errors: List[CommandError]) -> None: + def __init__(self, param: Parameter, literals: Tuple[Any, ...], errors: List[CommandError], argument: str = "") -> None: self.param: Parameter = param self.literals: Tuple[Any, ...] = literals self.errors: List[CommandError] = errors + self.argument: str = argument to_string = [repr(l) for l in literals] if len(to_string) > 2: