@@ -116,7 +116,7 @@ def required_pos_arguments(func: Callable[..., Any]) -> int:
116
116
return sum (p .default is p .empty for p in sig .parameters .values ())
117
117
118
118
119
- def make_converter_transformer (converter : Any ) -> Type [app_commands .Transformer ]:
119
+ def make_converter_transformer (converter : Any , parameter : Parameter ) -> Type [app_commands .Transformer ]:
120
120
try :
121
121
module = converter .__module__
122
122
except AttributeError :
@@ -126,14 +126,17 @@ def make_converter_transformer(converter: Any) -> Type[app_commands.Transformer]
126
126
converter = CONVERTER_MAPPING .get (converter , converter )
127
127
128
128
async def transform (cls , interaction : discord .Interaction , value : str ) -> Any :
129
+ ctx = interaction ._baton
130
+ ctx .current_parameter = parameter
131
+ ctx .current_argument = value
129
132
try :
130
133
if inspect .isclass (converter ) and issubclass (converter , Converter ):
131
134
if inspect .ismethod (converter .convert ):
132
- return await converter .convert (interaction . _baton , value )
135
+ return await converter .convert (ctx , value )
133
136
else :
134
- return await converter ().convert (interaction . _baton , value ) # type: ignore
137
+ return await converter ().convert (ctx , value ) # type: ignore
135
138
elif isinstance (converter , Converter ):
136
- return await converter .convert (interaction . _baton , value ) # type: ignore
139
+ return await converter .convert (ctx , value ) # type: ignore
137
140
except CommandError :
138
141
raise
139
142
except Exception as exc :
@@ -158,14 +161,16 @@ def make_greedy_transformer(converter: Any, parameter: Parameter) -> Type[app_co
158
161
async def transform (cls , interaction : discord .Interaction , value : str ) -> Any :
159
162
view = StringView (value )
160
163
result = []
164
+ ctx = interaction ._baton
165
+ ctx .current_parameter = parameter
161
166
while True :
162
167
view .skip_ws ()
163
- arg = view .get_quoted_word ()
168
+ ctx . current_argument = arg = view .get_quoted_word ()
164
169
if arg is None :
165
170
break
166
171
167
172
# This propagates the exception
168
- converted = await run_converters (interaction . _baton , converter , arg , parameter )
173
+ converted = await run_converters (ctx , converter , arg , parameter )
169
174
result .append (converted )
170
175
171
176
return result
@@ -228,7 +233,7 @@ def replace_parameter(
228
233
app_commands .rename (** renames )(callback )
229
234
230
235
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 ))
232
237
elif origin is Union :
233
238
if len (args ) == 2 and args [- 1 ] is _NoneType :
234
239
# Special case Optional[X] where X is a single type that can optionally be a converter
0 commit comments