From d973ff30b6c84433c6d0d61a2d3652be356abbb0 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 ed48d2760..3931c08c8 100644 --- a/discord/ext/commands/converter.py +++ b/discord/ext/commands/converter.py @@ -1321,7 +1321,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 262efed1e..48ae70bbb 100644 --- a/discord/ext/commands/errors.py +++ b/discord/ext/commands/errors.py @@ -918,12 +918,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: