Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion discord/commands/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
5 changes: 3 additions & 2 deletions discord/commands/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -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] = []
Expand Down Expand Up @@ -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
Expand Down