diff --git a/discord/app_commands/commands.py b/discord/app_commands/commands.py index 68abfce38..0508fb4a1 100644 --- a/discord/app_commands/commands.py +++ b/discord/app_commands/commands.py @@ -246,6 +246,11 @@ def _populate_autocomplete(params: Dict[str, CommandParameter], autocomplete: Di if param.type not in (AppCommandOptionType.string, AppCommandOptionType.number, AppCommandOptionType.integer): raise TypeError('autocomplete is only supported for integer, string, or number option types') + if param.is_choice_annotation(): + raise TypeError( + 'Choice annotation unsupported for autocomplete parameters, consider using a regular annotation instead' + ) + param.autocomplete = _validate_auto_complete_callback(callback) if autocomplete: @@ -589,6 +594,11 @@ class Command(Generic[GroupT, P, T]): if param.type not in (AppCommandOptionType.string, AppCommandOptionType.number, AppCommandOptionType.integer): raise TypeError('autocomplete is only supported for integer, string, or number option types') + if param.is_choice_annotation(): + raise TypeError( + 'Choice annotation unsupported for autocomplete parameters, consider using a regular annotation instead' + ) + param.autocomplete = _validate_auto_complete_callback(coro) return coro diff --git a/discord/app_commands/transformers.py b/discord/app_commands/transformers.py index 842e74bce..d10754092 100644 --- a/discord/app_commands/transformers.py +++ b/discord/app_commands/transformers.py @@ -124,6 +124,9 @@ class CommandParameter: return base + def is_choice_annotation(self) -> bool: + return getattr(self._annotation, '__discord_app_commands_is_choice__', False) + async def transform(self, interaction: Interaction, value: Any) -> Any: if hasattr(self._annotation, '__discord_app_commands_transformer__'): # This one needs special handling for type safety reasons