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

Member.top_role not updating when positions change #4087

Closed
3 tasks done
Silari opened this issue May 10, 2020 · 1 comment · Fixed by #4157
Closed
3 tasks done

Member.top_role not updating when positions change #4087

Silari opened this issue May 10, 2020 · 1 comment · Fixed by #4157
Labels
bug This is a bug with the library.
Milestone

Comments

@Silari
Copy link

Silari commented May 10, 2020

Summary

If a role position is changed, calling member.top_role does not update the top role if it has changed. It still shows whatever the old top position was.

Only similar issue still open is #2142 but that involved role creation and the cache, where these roles are being edited and the new position is set correctly.

Expected Results

The top_role property to always return the role with the highest position.

Actual Results

The old top role is still returned as the top role, despite it being moved to a lower position or another role being moved higher. The output of the following code in an on_message(message) event shows the issue.

msg = "Roles:"
for myrole in message.guild.me.roles:
    msg += " Name: " + myrole.name + " Position:" + str(myrole.position)
print(msg)
msg = "Top Role: " + message.guild.me.top_role.name + " " str(message.guild.me.top_role.position)
print(msg)

Roles: Name: @everyone Position:0 Name: PicartoBot-Dev Position:2 Name: Trixie Position:5
Top Role: Trixie 5

The highest role is Trixie, as it should be. After moving the Trixie role to just above @everyone (Position 1) and rerunning:

Roles: Name: @everyone Position:0 Name: PicartoBot-Dev Position:3 Name: Trixie Position:1
Top Role: Trixie 1

It still lists Trixie as the highest role, despite having updated the role with it's new position.

Looking at the code for Member.top_role, it seems like the list of roles should be sorted in ascending position order, but it's not being resorted when the role position is updated, thus causing top_role to return the wrong role.

Checklist

  • I have searched the open issues for duplicates.
  • I have shown the entire traceback, if possible.
  • I have removed my token from display, if visible.

System Information

  • Python v3.7.2-final
  • discord.py v1.3.3-final
  • aiohttp v3.6.2
  • websockets v6.0
  • system info: Windows 10 10.0.18362
@Rapptz Rapptz added the bug This is a bug with the library. label May 10, 2020
@Rapptz Rapptz added this to the 1.4 milestone May 10, 2020
@Rapptz
Copy link
Owner

Rapptz commented May 10, 2020

I believe this happens because the cache for roles is not invalidated upon roles being updated. Invalidating the cache at this stage becomes kind of expensive so I may have to reconsider the cache layer here to properly fix this. Unsure at the moment.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug This is a bug with the library.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants