Skip to content

Commit b2d5047

Browse files
Paillat-devDorukyumJustaSqu1d
authored
fix: 🐛 Set autocomplete instance method status on Option directly (#3082)
* 🐛 Set autocomplete instance method status on `Option` directly * 📝 CHANGELO * Update CHANGELOG.md Co-authored-by: JustaSqu1d <89910983+JustaSqu1d@users.noreply.github.com> Signed-off-by: Paillat <jeremiecotti@ik.me> --------- Signed-off-by: Dorukyum <53639936+Dorukyum@users.noreply.github.com> Signed-off-by: Paillat <jeremiecotti@ik.me> Co-authored-by: Dorukyum <53639936+Dorukyum@users.noreply.github.com> Co-authored-by: JustaSqu1d <89910983+JustaSqu1d@users.noreply.github.com>
1 parent f8fcd8c commit b2d5047

File tree

3 files changed

+6
-3
lines changed

3 files changed

+6
-3
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ These changes are available on the `master` branch, but have not yet been releas
4848
([#3061](https://github.com/Pycord-Development/pycord/pull/3061))
4949
- Fixed the update of a user's `primary_guild` to now cause an `on_user_update` event to
5050
fire. ([#3077](https://github.com/Pycord-Development/pycord/pull/3077))
51+
- Fixed an error when using methods from other classes regarding option autocompletes.
52+
([#3082](https://github.com/Pycord-Development/pycord/pull/3082))
5153

5254
### Removed
5355

discord/commands/core.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1121,7 +1121,7 @@ async def invoke_autocomplete_callback(self, ctx: AutocompleteContext):
11211121
ctx.value = op.get("value")
11221122
ctx.options = values
11231123

1124-
if option.autocomplete._is_instance_method:
1124+
if option._autocomplete_is_instance_method:
11251125
instance = getattr(option.autocomplete, "__self__", ctx.cog)
11261126
result = option.autocomplete(instance, ctx)
11271127
else:

discord/commands/options.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,7 @@ def __init__(
307307
self.default = kwargs.pop("default", None)
308308

309309
self._autocomplete: AutocompleteFunction | None = None
310+
self._autocomplete_is_instance_method: bool = False
310311
self.autocomplete = kwargs.pop("autocomplete", None)
311312
if len(enum_choices) > 25:
312313
self.choices: list[OptionChoice] = []
@@ -483,13 +484,13 @@ def autocomplete(self, value: AutocompleteFunction | None) -> None:
483484
self._autocomplete = value
484485
# this is done here so it does not have to be computed every time the autocomplete is invoked
485486
if self._autocomplete is not None:
486-
self._autocomplete._is_instance_method = ( # pyright: ignore [reportFunctionMemberAccess]
487+
self._autocomplete_is_instance_method = (
487488
sum(
488489
1
489490
for param in inspect.signature(
490491
self._autocomplete
491492
).parameters.values()
492-
if param.default == param.empty # pyright: ignore[reportAny]
493+
if param.default == param.empty
493494
and param.kind not in (param.VAR_POSITIONAL, param.VAR_KEYWORD)
494495
)
495496
== 2

0 commit comments

Comments
 (0)