diff --git a/CHANGELOG.md b/CHANGELOG.md index cb78469987..dd044d7072 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -31,6 +31,12 @@ These changes are available on the `master` branch, but have not yet been releas - Removed `@client.once()` in favour of `@client.listen(once=True)`. ([#1957](https://github.com/Pycord-Development/pycord/pull/1957)) +### Fixed + +- Fixed `AttributeError` caused by + [#1957](https://github.com/Pycord-Development/pycord/pull/1957) when using listeners + in cogs. ([#1989](https://github.com/Pycord-Development/pycord/pull/1989)) + ## [2.4.1] - 2023-03-20 ### Changed diff --git a/discord/client.py b/discord/client.py index a6849a205b..654219a0bd 100644 --- a/discord/client.py +++ b/discord/client.py @@ -442,8 +442,18 @@ def dispatch(self, event: str, *args: Any, **kwargs: Any) -> None: # Schedule additional handlers registered with @listen for coro in self._event_handlers.get(method, []): self._schedule_event(coro, method, *args, **kwargs) - if coro._once: - once_listeners.append(coro) + + try: + if coro._once: # added using @listen() + once_listeners.append(coro) + + except AttributeError: # added using @Cog.add_listener() + # https://github.com/Pycord-Development/pycord/pull/1989 + # Although methods are similar to functions, attributes can't be added to them. + # This means that we can't add the `_once` attribute in the `add_listener` method + # and can only be added using the `@listen` decorator. + + continue # remove the once listeners for coro in once_listeners: