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

AttributeError with raw_status in on_relationship_update event #473

Closed LostXOR closed 1 year ago

LostXOR commented 1 year ago

Summary

An AttributeError sometimes occurs when trying to read the raw_status attribute of a Relationship

Reproduction Steps

Run the code below, then open Discord and friend a user. The error will occur.

Code

import discord

class Client(discord.Client):
    async def on_ready(self):
        print("Connected.")
    async def on_relationship_update(self, before, after):
        print(after.raw_status)

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

Expected Results

The code should print the Relationship's raw status when a relationship update occurs.

Actual Results

An error occurs:

Ignoring exception in on_relationship_update
Traceback (most recent call last):
  File "/.../discord/client.py", line 462, in _run_event
    await coro(*args, **kwargs)
  File "/.../test.py", line 7, in on_relationship_update
    print(after.raw_status)
  File "/.../discord/relationship.py", line 169, in raw_status
    return self.presence.client_status.status
  File "/.../discord/relationship.py", line 145, in presence
    return self._presence or state._presences.get(self.user.id) or state.create_offline_presence()
AttributeError: 'Relationship' object has no attribute '_presence'

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

This should be fixed now, thanks.