-
-
Notifications
You must be signed in to change notification settings - Fork 481
Labels
bugSomething isn't workingSomething isn't working
Description
Summary
An async staticmethod cannot be used as an option autocomplete callback function. A non-async staticmethod can be used.
Reproduction Steps
Use code below:
Minimal Reproducible Code
import os
import logging
from discord import *
from dotenv import load_dotenv
logging.basicConfig(level=logging.INFO)
load_dotenv()
TOKEN = os.getenv("TOKEN_2")
bot = Bot(intents=Intents.all())
class MyCog(Cog):
@staticmethod
async def autocomplete(ctx: AutocompleteContext): # Works w/out async
return ["A", "B", "C", "D"]
@slash_command()
@option(name="option", autocomplete=autocomplete)
async def test(self, ctx: ApplicationContext, option: str):
await ctx.respond(f"You chose {option}")
bot.add_cog(MyCog())
bot.run(TOKEN)
Expected Results
A B C D to show up as options
Actual Results

ERROR:asyncio:Task exception was never retrieved
future: <Task finished name='Task-11' coro=<ApplicationCommandMixin.on_application_command_auto_complete.<locals>.callback() done, defined at C:\Users\jerem\Documents\pycord\pycord\discord\bot.py:893> exception=TypeError("'coroutine' object is not iterable")>
Traceback (most recent call last):
File "C:\Users\jerem\Documents\pycord\pycord\discord\bot.py", line 896, in callback
return await command.invoke_autocomplete_callback(ctx)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\jerem\Documents\pycord\pycord\discord\commands\core.py", line 1133, in invoke_autocomplete_callback
for o in result
^^^^^^
TypeError: 'coroutine' object is not iterable
C:\Users\jerem\AppData\Roaming\uv\python\cpython-3.12.11-windows-x86_64-none\Lib\asyncio\events.py:88: RuntimeWarning: coroutine 'MyCog.autocomplete' was never awaited
self._context.run(self._callback, *self._args)
RuntimeWarning: Enable tracemalloc to get the object allocation traceback
Intents
n/a
System Information
n/a
Checklist
- I have searched the open issues for duplicates.
- I have shown the entire traceback, if possible.
- I have removed my token from display, if visible.
Additional Context
No response
AceHanded
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't working