Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove unnecessary instance check in autocomplete #1643

Merged
merged 2 commits into from
Sep 23, 2022
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 12 additions & 13 deletions discord/bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -756,20 +756,19 @@ async def process_application_commands(self, interaction: Interaction, auto_sync
await self.invoke_application_command(ctx)

async def on_application_command_auto_complete(self, interaction: Interaction, command: ApplicationCommand) -> None:
if isinstance(command, SlashCommand):
async def callback() -> None:
ctx = await self.get_autocomplete_context(interaction)
ctx.command = command
return await command.invoke_autocomplete_callback(ctx)
async def callback() -> None:
ctx = await self.get_autocomplete_context(interaction)
ctx.command = command
return await command.invoke_autocomplete_callback(ctx)

autocomplete_task = self._bot.loop.create_task(callback())
try:
await self._bot.wait_for("application_command_auto_complete", check=lambda i, c: c == command, timeout=3)
except asyncio.TimeoutError:
return
else:
if not autocomplete_task.done():
autocomplete_task.cancel()
autocomplete_task = self._bot.loop.create_task(callback())
try:
await self._bot.wait_for("application_command_auto_complete", check=lambda i, c: c == command, timeout=3)
except asyncio.TimeoutError:
return
else:
if not autocomplete_task.done():
autocomplete_task.cancel()

def slash_command(self, **kwargs):
"""A shortcut decorator that invokes :func:`command` and adds it to
Expand Down