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

Add support for autocomplete #277

Closed
Closed
Show file tree
Hide file tree
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
Prev Previous commit
Next Next commit
Make suggested changes
  • Loading branch information
CodeWithSwastik committed Oct 18, 2021
commit 282b9cf49bc4bb050f35d4eb7113c4b04c95910e
10 changes: 7 additions & 3 deletions discord/app/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
import asyncio
import inspect
from collections import OrderedDict
from typing import Callable, Dict, List, Optional, Union
from typing import Callable, Dict, List, Optional, Union, TYPE_CHECKING

from ..enums import SlashCommandOptionType
from ..member import Member
Expand All @@ -38,6 +38,10 @@
from ..utils import find, get_or_fetch
from ..errors import NotFound

if TYPE_CHECKING:
from ..interactions import Interaction



class ApplicationCommand:
def __repr__(self):
Expand Down Expand Up @@ -167,7 +171,7 @@ async def invoke(self, ctx: InteractionContext) -> None:
kwargs[o.name] = o.default
await self.callback(ctx, **kwargs)

async def invoke_autocomplete_callback(self, interaction):
async def invoke_autocomplete_callback(self, interaction: Interaction):
for op in interaction.data.get("options", []):
if op.get("focused", False):
option = find(lambda o: o.name == op["name"], self.options)
Expand All @@ -176,7 +180,7 @@ async def invoke_autocomplete_callback(self, interaction):
o if isinstance(o, OptionChoice) else OptionChoice(o)
for o in result
]
await interaction.response.send_autocomplete_result(choices = choices)
await interaction.response.send_autocomplete_result(choices=choices)

class Option:
def __init__(
Expand Down
2 changes: 1 addition & 1 deletion discord/bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ async def handle_interaction(self, interaction: Interaction) -> None:
except KeyError:
self.dispatch("unknown_command", interaction)
else:
if interaction.type == InteractionType.application_command:
if interaction.type is InteractionType.application_command:
context = await self.get_application_context(interaction)
await command.invoke(context)
else:
Expand Down