dolfies / discord.py-self

A fork of the popular discord.py for user accounts.
https://discordpy-self.rtfd.io/en/latest/
MIT License
665 stars 155 forks source link

on_presence_update is called with a Relationship instead of a Member #474

Closed LostXOR closed 1 year ago

LostXOR commented 1 year ago

Summary

The event on_presence_update is called a third time with a Relationship instead of a Member if the user is a friend.

Reproduction Steps

Run the code. While the code is running, have a server member who is also a friend change their status.

Code

import discord

class Client(discord.Client):
    async def on_ready(self):
        print("Connected.")
    async def on_presence_update(self, before, after):
        print(type(after).__name__) # Print type of "after" argument

client = Client()
client.run("<token>")

Expected Results

The program should print

Member
Member

(I assume the event triggering twice is by design. If not, that's another bug.)

Actual Results

The program prints

Member
Member
Relationship

or sometimes

Relationship
Member
Member

As shown here on the API reference, on_presence_update should be called with two Member objects, not a Relationship.

System Information

discord.py-self is not installed globally, and I'm not sure how to run that command on a local module. I'm using the latest commit from 2 days ago.

Checklist

Additional Information

No response

dolfies commented 1 year ago

Must've forgotten about this when documenting the presence changes sweep.

So the way user presence works is kinda weird (without even getting into subscriptions). For every guild member there is a per-guild presence. However, there's also an "overall" user presence sent to friends/implicit relationships independent of any guild. Because of this, for these presences there is not a Member object, only a Relationship object.

For now, I'm dispatching the same presence_update for both. Maybe a separate event needs to be introduced. Either way, documentation must be updated.

dolfies commented 1 year ago

I ended up leaving this as-is and documenting the change for release. This might get separated in v2.1 or later, but I need more general feedback.