Discord.py: Spotify objects with different songs are equal in on_member_update

Created on 22 Apr 2019  路  3Comments  路  Source: Rapptz/discord.py

Summary

When a song progresses to a different one on Spotify, on_member_update is called, but before == after, and before.activities == after.activities.

Seems to be caused by hashing the session id, which doesn't change between songs.

Reproduction Steps

@bot.event
async def on_member_update(b,a)
    print(b==a)
    print(b.activities == a.activities)

Expected Results

Output:

False
False

Actual Results

Output:

True
True

Checklist

  • [x] I have searched the open issues for duplicates.
  • [x] ~I have shown the entire traceback, if possible.~ N/A
  • [x] ~I have removed my token from display, if visible.~ N/A

System Information

  • discord.py version: 1.0.1
  • Python version: 3.7.1
  • Operating system: Platform-independent (Tested on Centos 7, Win7/10)
bug

All 3 comments

Doing a quick check reveals that comparing Member only compares the member ID and nothing else, as written here.
Assuming Member.activities has only an instance of Spotify, comparing the two only compares the session ID, as written here.

A simple way to represent this is:

class MyClass:
    def __init__(self):
        self.id = 5
        self.something_else = 2

    def __eq__(self, other):
        return self.id == other.id

my_list = [MyClass()]

m = MyClass()
m.something_else = 6
my_other_list = [m]

print(my_list == my_other_list)  # True because both instances of MyClass have the same ID

A way to work around this would be to compare the track_id of the Spotify instances instead.

The behaviour of Member.__eq__ is not going to change.

However, the behaviour of Spotify.__eq__ could be better I suppose.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

rektile picture rektile  路  18Comments

downloadpizza picture downloadpizza  路  14Comments

johndoe434 picture johndoe434  路  21Comments

SakiiR picture SakiiR  路  17Comments

wolfclaws picture wolfclaws  路  17Comments