Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature - Raw Presence Updates #10048

Open
wants to merge 31 commits into
base: master
Choose a base branch
from

Conversation

EvieePy
Copy link
Contributor

@EvieePy EvieePy commented Dec 21, 2024

Summary

A current limitation of the library is not being able to listen to presence updates without meeting certain requirements, namely needing both member intents and a member and guild cache. In cases where these requirements are not available or desired, presence updates are still received and discarded. This PR adds functionality for the on_raw_presence_update event, which allows anyone not subscribed to member intents or not using a member or guild cache to receive presence update events.

Currently the implementation is semi opt-in, allowing anyone to manually enable or disable raw presences via the new Client keyword parameter. By default this event is only enabled automatically when a user has presences intents enabled and members intents disabled, as this would mean they could not receive the currently available on_presence_update event.

Added

  • on_raw_presence_update
  • RawPresenceUpdateEvent model received in the event and used in Member to update presence data.
  • Client(enable_raw_presences=...) keyword argument.
  • ClientStatus - Previously a private internal. The model representing Client Status data from discord.
  • Member.client_status - Previously a private internal.

Checklist

  • If code changes were made then they have been tested.
    • I have updated the documentation to reflect the changes.
  • This PR fixes an issue.
  • This PR adds something new (e.g. new method or parameters).
  • This PR is a breaking change (e.g. methods or parameters removed/renamed)
  • This PR is not a code change (e.g. documentation, README, ...)

Copy link
Contributor

@MCausc78 MCausc78 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I actually needed this feature. Thanks.

discord/client.py Outdated Show resolved Hide resolved
discord/presences.py Outdated Show resolved Hide resolved
discord/presences.py Outdated Show resolved Hide resolved
discord/presences.py Outdated Show resolved Hide resolved
discord/member.py Show resolved Hide resolved
discord/presences.py Show resolved Hide resolved
docs/api.rst Outdated Show resolved Hide resolved
discord/presences.py Outdated Show resolved Hide resolved
discord/member.py Outdated Show resolved Hide resolved
Comment on lines +153 to +154
def _create_activities(self, data: PartialPresenceUpdate, state: ConnectionState) -> None:
self._activities = tuple(create_activity(d, state) for d in data['activities'])
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this should be done outside of __init__, as it'll be called on every RawPresenceUpdate anyway since you either dispatch raw_presence_update, call Member._presence_update, or even do both.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants