diff --git a/CHANGELOG.md b/CHANGELOG.md index 5ca67e273f..b80f2722f5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -48,6 +48,8 @@ These changes are available on the `master` branch, but have not yet been releas ([#3061](https://github.com/Pycord-Development/pycord/pull/3061)) - Fixed the update of a user's `primary_guild` to now cause an `on_user_update` event to fire. ([#3077](https://github.com/Pycord-Development/pycord/pull/3077)) +- Fixed an error when using methods from other classes regarding option autocompletes. + ([#3082](https://github.com/Pycord-Development/pycord/pull/3082)) ### Removed diff --git a/discord/commands/core.py b/discord/commands/core.py index a184a6fcae..499e326a61 100644 --- a/discord/commands/core.py +++ b/discord/commands/core.py @@ -1121,7 +1121,7 @@ async def invoke_autocomplete_callback(self, ctx: AutocompleteContext): ctx.value = op.get("value") ctx.options = values - if option.autocomplete._is_instance_method: + if option._autocomplete_is_instance_method: instance = getattr(option.autocomplete, "__self__", ctx.cog) result = option.autocomplete(instance, ctx) else: diff --git a/discord/commands/options.py b/discord/commands/options.py index 1613630bc0..e62d81d80a 100644 --- a/discord/commands/options.py +++ b/discord/commands/options.py @@ -307,6 +307,7 @@ def __init__( self.default = kwargs.pop("default", None) self._autocomplete: AutocompleteFunction | None = None + self._autocomplete_is_instance_method: bool = False self.autocomplete = kwargs.pop("autocomplete", None) if len(enum_choices) > 25: self.choices: list[OptionChoice] = [] @@ -483,13 +484,13 @@ def autocomplete(self, value: AutocompleteFunction | None) -> None: self._autocomplete = value # this is done here so it does not have to be computed every time the autocomplete is invoked if self._autocomplete is not None: - self._autocomplete._is_instance_method = ( # pyright: ignore [reportFunctionMemberAccess] + self._autocomplete_is_instance_method = ( sum( 1 for param in inspect.signature( self._autocomplete ).parameters.values() - if param.default == param.empty # pyright: ignore[reportAny] + if param.default == param.empty and param.kind not in (param.VAR_POSITIONAL, param.VAR_KEYWORD) ) == 2