diff --git a/interactions/client/context.py b/interactions/client/context.py index 2c287c014..3e9677efb 100644 --- a/interactions/client/context.py +++ b/interactions/client/context.py @@ -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()