Skip to content

Commit 5f6355d

Browse files
Allow sync callbacks for autocomplete
1 parent 7993edb commit 5f6355d

File tree

1 file changed

+5
-6
lines changed

1 file changed

+5
-6
lines changed

discord/commands/commands.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -538,7 +538,11 @@ async def invoke_autocomplete_callback(self, interaction: Interaction):
538538
for i in interaction.data["options"]
539539
})
540540
ctx = AutocompleteContext(interaction, command=self, focused=option, value=op.get("value"), options=values)
541-
result = await option.autocomplete(ctx)
541+
if asyncio.iscoroutinefunction(option.autocomplete):
542+
result = await option.autocomplete(ctx)
543+
else:
544+
result = option.autocomplete(ctx)
545+
542546
choices = [
543547
o if isinstance(o, OptionChoice) else OptionChoice(o)
544548
for o in result
@@ -638,11 +642,6 @@ def __init__(
638642
raise TypeError(f"Expected {minmax_typehint} for max_value, got \"{type(self.max_value).__name__}\"")
639643

640644
self.autocomplete = kwargs.pop("autocomplete", None)
641-
if (
642-
self.autocomplete and
643-
not asyncio.iscoroutinefunction(self.autocomplete)
644-
):
645-
raise TypeError("Autocomplete callback must be a coroutine.")
646645

647646
def to_dict(self) -> Dict:
648647
as_dict = {

0 commit comments

Comments
 (0)