mirror of
https://github.com/Rapptz/discord.py.git
synced 2025-07-02 00:00:02 +00:00
Fix autocomplete bindings not working for transformer instances
This commit is contained in:
parent
5538cd501c
commit
c735682ac6
@ -226,21 +226,22 @@ def validate_context_menu_name(name: str) -> str:
|
|||||||
|
|
||||||
|
|
||||||
def _validate_auto_complete_callback(
|
def _validate_auto_complete_callback(
|
||||||
callback: AutocompleteCallback[GroupT, ChoiceT],
|
callback: AutocompleteCallback[GroupT, ChoiceT]
|
||||||
skip_binding: bool = False,
|
|
||||||
) -> AutocompleteCallback[GroupT, ChoiceT]:
|
) -> AutocompleteCallback[GroupT, ChoiceT]:
|
||||||
|
# This function needs to ensure the following is true:
|
||||||
|
# If self.foo is passed then don't pass command.binding to the callback
|
||||||
|
# If Class.foo is passed then it is assumed command.binding has to be passed
|
||||||
|
# If free_function_foo is passed then no binding should be passed at all
|
||||||
|
# Passing command.binding is mandated by pass_command_binding
|
||||||
|
|
||||||
binding = getattr(callback, '__self__', None)
|
binding = getattr(callback, '__self__', None)
|
||||||
if binding is not None:
|
pass_command_binding = binding is None and is_inside_class(callback)
|
||||||
callback = callback.__func__
|
|
||||||
requires_binding = True
|
|
||||||
else:
|
|
||||||
requires_binding = is_inside_class(callback) or skip_binding
|
|
||||||
|
|
||||||
callback.requires_binding = requires_binding
|
# 'method' objects can't have dynamic attributes
|
||||||
callback.binding = binding
|
if binding is None:
|
||||||
|
callback.pass_command_binding = pass_command_binding
|
||||||
|
|
||||||
required_parameters = 2 + requires_binding
|
required_parameters = 2 + pass_command_binding
|
||||||
params = inspect.signature(callback).parameters
|
params = inspect.signature(callback).parameters
|
||||||
if len(params) != required_parameters:
|
if len(params) != required_parameters:
|
||||||
raise TypeError(f'autocomplete callback {callback.__qualname__!r} requires either 2 or 3 parameters to be passed')
|
raise TypeError(f'autocomplete callback {callback.__qualname__!r} requires either 2 or 3 parameters to be passed')
|
||||||
@ -714,8 +715,8 @@ class Command(Generic[GroupT, P, T]):
|
|||||||
await interaction.response.autocomplete([])
|
await interaction.response.autocomplete([])
|
||||||
return
|
return
|
||||||
|
|
||||||
if param.autocomplete.requires_binding:
|
if getattr(param.autocomplete, 'pass_command_binding', False):
|
||||||
binding = param.autocomplete.binding or self.binding
|
binding = self.binding
|
||||||
if binding is not None:
|
if binding is not None:
|
||||||
choices = await param.autocomplete(binding, interaction, value)
|
choices = await param.autocomplete(binding, interaction, value)
|
||||||
else:
|
else:
|
||||||
|
@ -810,6 +810,6 @@ def annotation_to_parameter(annotation: Any, parameter: inspect.Parameter) -> Co
|
|||||||
if inner.autocomplete.__func__ is not Transformer.autocomplete:
|
if inner.autocomplete.__func__ is not Transformer.autocomplete:
|
||||||
from .commands import _validate_auto_complete_callback
|
from .commands import _validate_auto_complete_callback
|
||||||
|
|
||||||
result.autocomplete = _validate_auto_complete_callback(inner.autocomplete, skip_binding=True)
|
result.autocomplete = _validate_auto_complete_callback(inner.autocomplete)
|
||||||
|
|
||||||
return result
|
return result
|
||||||
|
Loading…
x
Reference in New Issue
Block a user