Skip to content
Merged
Changes from all commits
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
52 changes: 28 additions & 24 deletions interactions/client/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -518,32 +518,36 @@ async def populate(self, choices: Union[Choice, List[Choice]]) -> List[Choice]:
"""

async def func():
if choices:
_choices: list = []
if all(isinstance(choice, Choice) for choice in choices):
_choices = [choice._json for choice in choices]
elif all(
isinstance(choice, dict) and all(isinstance(x, str) for x in choice)
for choice in choices
):
_choices = list(choices)
elif isinstance(choices, Choice):
_choices = [choices._json]
else:
raise InteractionException(
6, message="Autocomplete choice items must be of type Choice"
)

await self.client.create_interaction_response(
token=self.token,
application_id=int(self.id),
data={
"type": InteractionCallbackType.APPLICATION_COMMAND_AUTOCOMPLETE_RESULT.value,
"data": {"choices": _choices},
},
_choices: Union[list, None] = []

if not choices or (isinstance(choices, list) and len(choices) == 0):
_choices = None
elif isinstance(choices, Choice):
_choices.append(choices._json)
elif isinstance(choices, list) and all(
isinstance(choice, Choice) for choice in choices
):
_choices = [choice._json for choice in choices]
elif all(
isinstance(choice, dict) and all(isinstance(x, str) for x in choice)
for choice in choices
):
_choices = list(choices)
else:
raise InteractionException(
6, message="Autocomplete choice items must be of type Choice"
)

return _choices
await self.client.create_interaction_response(
token=self.token,
application_id=int(self.id),
data={
"type": InteractionCallbackType.APPLICATION_COMMAND_AUTOCOMPLETE_RESULT.value,
"data": {"choices": _choices},
},
)

return _choices

return await func()

Expand Down