@@ -116,7 +116,7 @@ def required_pos_arguments(func: Callable[..., Any]) -> int:
116116 return sum (p .default is p .empty for p in sig .parameters .values ())
117117
118118
119- def make_converter_transformer (converter : Any ) -> Type [app_commands .Transformer ]:
119+ def make_converter_transformer (converter : Any , parameter : Parameter ) -> Type [app_commands .Transformer ]:
120120 try :
121121 module = converter .__module__
122122 except AttributeError :
@@ -126,14 +126,17 @@ def make_converter_transformer(converter: Any) -> Type[app_commands.Transformer]
126126 converter = CONVERTER_MAPPING .get (converter , converter )
127127
128128 async def transform (cls , interaction : discord .Interaction , value : str ) -> Any :
129+ ctx = interaction ._baton
130+ ctx .current_parameter = parameter
131+ ctx .current_argument = value
129132 try :
130133 if inspect .isclass (converter ) and issubclass (converter , Converter ):
131134 if inspect .ismethod (converter .convert ):
132- return await converter .convert (interaction . _baton , value )
135+ return await converter .convert (ctx , value )
133136 else :
134- return await converter ().convert (interaction . _baton , value ) # type: ignore
137+ return await converter ().convert (ctx , value ) # type: ignore
135138 elif isinstance (converter , Converter ):
136- return await converter .convert (interaction . _baton , value ) # type: ignore
139+ return await converter .convert (ctx , value ) # type: ignore
137140 except CommandError :
138141 raise
139142 except Exception as exc :
@@ -158,14 +161,16 @@ def make_greedy_transformer(converter: Any, parameter: Parameter) -> Type[app_co
158161 async def transform (cls , interaction : discord .Interaction , value : str ) -> Any :
159162 view = StringView (value )
160163 result = []
164+ ctx = interaction ._baton
165+ ctx .current_parameter = parameter
161166 while True :
162167 view .skip_ws ()
163- arg = view .get_quoted_word ()
168+ ctx . current_argument = arg = view .get_quoted_word ()
164169 if arg is None :
165170 break
166171
167172 # This propagates the exception
168- converted = await run_converters (interaction . _baton , converter , arg , parameter )
173+ converted = await run_converters (ctx , converter , arg , parameter )
169174 result .append (converted )
170175
171176 return result
@@ -228,14 +233,14 @@ def replace_parameter(
228233 app_commands .rename (** renames )(callback )
229234
230235 elif is_converter (converter ) or converter in CONVERTER_MAPPING :
231- param = param .replace (annotation = make_converter_transformer (converter ))
236+ param = param .replace (annotation = make_converter_transformer (converter , original ))
232237 elif origin is Union :
233238 if len (args ) == 2 and args [- 1 ] is _NoneType :
234239 # Special case Optional[X] where X is a single type that can optionally be a converter
235240 inner = args [0 ]
236241 is_inner_tranformer = is_transformer (inner )
237242 if is_converter (inner ) and not is_inner_tranformer :
238- param = param .replace (annotation = Optional [make_converter_transformer (inner )]) # type: ignore
243+ param = param .replace (annotation = Optional [make_converter_transformer (inner , original )]) # type: ignore
239244 else :
240245 raise
241246 elif origin :
0 commit comments