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
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 12 additions & 2 deletions discord/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down