Skip to content

Commit

Permalink
fix: attribute error with listeners in cogs (#1989)
Browse files Browse the repository at this point in the history
* fix attribute error

Signed-off-by: Om <92863779+Om1609@users.noreply.github.com>

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Revert "[pre-commit.ci] auto fixes from pre-commit.com hooks"

This reverts commit 3375d38.

* Revert "fix attribute error"

This reverts commit b8733f2.

* fix using EAPF

* Changelog and comments

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Update CHANGELOG.md

Signed-off-by: Om <92863779+Om1609@users.noreply.github.com>

* Update CHANGELOG.md

Co-authored-by: BobDotCom <71356958+BobDotCom@users.noreply.github.com>
Signed-off-by: Om <92863779+Om1609@users.noreply.github.com>

---------

Signed-off-by: Om <92863779+Om1609@users.noreply.github.com>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: BobDotCom <71356958+BobDotCom@users.noreply.github.com>
  • Loading branch information
3 people authored Mar 31, 2023
1 parent 93c28aa commit 614f794
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
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

0 comments on commit 614f794

Please sign in to comment.