Skip to content

Commit 3382447

Browse files
committed
✨ Allow for functools.partials and such as autocomplete
1 parent cab0a37 commit 3382447

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

discord/commands/core.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1095,7 +1095,7 @@ async def invoke_autocomplete_callback(self, ctx: AutocompleteContext):
10951095
ctx.value = op.get("value")
10961096
ctx.options = values
10971097

1098-
if len(inspect.signature(option.autocomplete).parameters) == 2:
1098+
if option.autocomplete._is_instance_method:
10991099
instance = getattr(option.autocomplete, "__self__", ctx.cog)
11001100
result = option.autocomplete(instance, ctx)
11011101
else:

discord/commands/options.py

+14
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,20 @@ def __init__(
285285
for o in kwargs.pop("choices", [])
286286
]
287287

288+
# this is done here so it does not have to be computed every time the autocomplete is invoked
289+
if self.autocomplete:
290+
self.autocomplete._is_instance_method: bool = (
291+
sum(
292+
1
293+
for param in inspect.signature(
294+
self.autocomplete
295+
).parameters.values()
296+
if param.default == param.empty
297+
and param.kind not in (param.VAR_POSITIONAL, param.VAR_KEYWORD)
298+
)
299+
== 2
300+
)
301+
288302
if self.input_type == SlashCommandOptionType.integer:
289303
minmax_types = (int, type(None))
290304
minmax_typehint = Optional[int]

0 commit comments

Comments
 (0)