mirror of
https://github.com/Rapptz/discord.py.git
synced 2025-09-08 10:53:10 +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:
@ -246,6 +246,11 @@ def _populate_autocomplete(params: Dict[str, CommandParameter], autocomplete: Di
|
|||||||
if param.type not in (AppCommandOptionType.string, AppCommandOptionType.number, AppCommandOptionType.integer):
|
if param.type not in (AppCommandOptionType.string, AppCommandOptionType.number, AppCommandOptionType.integer):
|
||||||
raise TypeError('autocomplete is only supported for integer, string, or number option types')
|
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)
|
param.autocomplete = _validate_auto_complete_callback(callback)
|
||||||
|
|
||||||
if autocomplete:
|
if autocomplete:
|
||||||
@ -589,6 +594,11 @@ class Command(Generic[GroupT, P, T]):
|
|||||||
if param.type not in (AppCommandOptionType.string, AppCommandOptionType.number, AppCommandOptionType.integer):
|
if param.type not in (AppCommandOptionType.string, AppCommandOptionType.number, AppCommandOptionType.integer):
|
||||||
raise TypeError('autocomplete is only supported for integer, string, or number option types')
|
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)
|
param.autocomplete = _validate_auto_complete_callback(coro)
|
||||||
return coro
|
return coro
|
||||||
|
|
||||||
|
@ -124,6 +124,9 @@ class CommandParameter:
|
|||||||
|
|
||||||
return base
|
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:
|
async def transform(self, interaction: Interaction, value: Any) -> Any:
|
||||||
if hasattr(self._annotation, '__discord_app_commands_transformer__'):
|
if hasattr(self._annotation, '__discord_app_commands_transformer__'):
|
||||||
# This one needs special handling for type safety reasons
|
# This one needs special handling for type safety reasons
|
||||||
|
Reference in New Issue
Block a user