diff --git a/discord/ext/commands/context.py b/discord/ext/commands/context.py index e48a01f86..eb6b59768 100644 --- a/discord/ext/commands/context.py +++ b/discord/ext/commands/context.py @@ -96,6 +96,11 @@ class Context(discord.abc.Messageable, Generic[BotT]): The parameter that is currently being inspected and converted. This is only of use for within converters. + .. versionadded:: 2.0 + current_argument: Optional[:class:`str`] + The argument string of the :attr:`current_parameter` that is currently being converted. + This is only of use for within converters. + .. versionadded:: 2.0 prefix: Optional[:class:`str`] The prefix that was used to invoke the command. @@ -141,6 +146,7 @@ class Context(discord.abc.Messageable, Generic[BotT]): subcommand_passed: Optional[str] = None, command_failed: bool = False, current_parameter: Optional[inspect.Parameter] = None, + current_argument: Optional[str] = None, ): self.message: Message = message self.bot: BotT = bot @@ -155,6 +161,7 @@ class Context(discord.abc.Messageable, Generic[BotT]): self.subcommand_passed: Optional[str] = subcommand_passed self.command_failed: bool = command_failed self.current_parameter: Optional[inspect.Parameter] = current_parameter + self.current_argument: Optional[str] = current_argument self._state: ConnectionState = self.message._state async def invoke(self, command: Command[CogT, P, T], /, *args: P.args, **kwargs: P.kwargs) -> T: diff --git a/discord/ext/commands/core.py b/discord/ext/commands/core.py index db9f0a07f..c43b4320e 100644 --- a/discord/ext/commands/core.py +++ b/discord/ext/commands/core.py @@ -604,10 +604,10 @@ class Command(_BaseCommand, Generic[CogT, P, T]): previous = view.index if consume_rest_is_special: - argument = view.read_rest().strip() + ctx.current_argument = argument = view.read_rest().strip() else: try: - argument = view.get_quoted_word() + ctx.current_argument = argument = view.get_quoted_word() except ArgumentParsingError as exc: if self._is_typing_optional(param.annotation): view.index = previous @@ -630,7 +630,7 @@ class Command(_BaseCommand, Generic[CogT, P, T]): view.skip_ws() try: - argument = view.get_quoted_word() + ctx.current_argument = argument = view.get_quoted_word() value = await run_converters(ctx, converter, argument, param) # type: ignore except (CommandError, ArgumentParsingError): view.index = previous @@ -646,7 +646,7 @@ class Command(_BaseCommand, Generic[CogT, P, T]): view = ctx.view previous = view.index try: - argument = view.get_quoted_word() + ctx.current_argument = argument = view.get_quoted_word() value = await run_converters(ctx, converter, argument, param) # type: ignore except (CommandError, ArgumentParsingError): view.index = previous @@ -754,7 +754,7 @@ class Command(_BaseCommand, Generic[CogT, P, T]): # kwarg only param denotes "consume rest" semantics if self.rest_is_raw: converter = get_converter(param) - argument = view.read_rest() + ctx.current_argument = argument = view.read_rest() kwargs[name] = await run_converters(ctx, converter, argument, param) else: kwargs[name] = await self.transform(ctx, param)