Skip to content

Commit 6c45c44

Browse files
Add optional third parameter for autocomplete
1 parent 499357c commit 6c45c44

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

discord/commands/commands.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -491,15 +491,24 @@ async def _invoke(self, ctx: ApplicationContext) -> None:
491491
await self.callback(ctx, **kwargs)
492492

493493
async def invoke_autocomplete_callback(self, interaction: Interaction):
494+
values = { i.name: i.default for i in self.options }
495+
494496
for op in interaction.data.get("options", []):
495497
if op.get("focused", False):
496498
option = find(lambda o: o.name == op["name"], self.options)
497-
result = await option.autocomplete(interaction, op.get("value", None))
499+
values.update({
500+
i["name"]:i["value"]
501+
for i in interaction.data["options"]
502+
})
503+
# This will only pass args depending on the argcount
504+
arg_count = option.autocomplete.__code__.co_argcount
505+
args = [interaction, op.get("value", None), values][:arg_count]
506+
result = await option.autocomplete(*args)
498507
choices = [
499508
o if isinstance(o, OptionChoice) else OptionChoice(o)
500509
for o in result
501510
]
502-
await interaction.response.send_autocomplete_result(choices=choices)
511+
return await interaction.response.send_autocomplete_result(choices=choices)
503512

504513
def qualified_name(self):
505514
return self.name

0 commit comments

Comments
 (0)