mirror of
https://github.com/Rapptz/discord.py.git
synced 2025-04-19 15:36:02 +00:00
Forbid Choice annotations being used with autocomplete parameters
Since the Choice are synthetic, the library doesn't have a pre-populated list of choices to know what to use as the resulting value.
This commit is contained in:
parent
698d1e12a1
commit
27dd986858
@ -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
|
||||
|
||||
|
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user