aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRapptz <[email protected]>2017-08-29 16:23:29 -0400
committerRapptz <[email protected]>2017-08-29 16:24:04 -0400
commit62df23633af8d0f243b540eb5976b88ad898a060 (patch)
treeb95dfd21ab694a1b1173b810dee3bcad7095db8e
parentUpdate embed property doc grammar (diff)
downloaddiscord.py-62df23633af8d0f243b540eb5976b88ad898a060.tar.xz
discord.py-62df23633af8d0f243b540eb5976b88ad898a060.zip
Sort roles by hierarchy instead of by ID.
Fixes #741
-rw-r--r--discord/member.py27
1 files changed, 9 insertions, 18 deletions
diff --git a/discord/member.py b/discord/member.py
index 894b0539..50da6a82 100644
--- a/discord/member.py
+++ b/discord/member.py
@@ -139,7 +139,8 @@ class Member(discord.abc.Messageable, _BaseUser):
----------
roles
A list of :class:`Role` that the member belongs to. Note that the first element of this
- list is always the default '@everyone' role.
+ list is always the default '@everyone' role. These roles are sorted by their position
+ in the role hierarchy.
joined_at : `datetime.datetime`
A datetime object that specifies the date and time in UTC that the member joined the guild for
the first time.
@@ -196,8 +197,8 @@ class Member(discord.abc.Messageable, _BaseUser):
if role is not None:
self.roles.append(role)
- # sort the roles by ID since they can be "randomised"
- self.roles.sort(key=lambda r: r.id)
+ # sort the roles by hierarchy since they can be "randomised"
+ self.roles.sort()
def _update(self, data, user=None):
if user:
@@ -238,21 +239,15 @@ class Member(discord.abc.Messageable, _BaseUser):
There is an alias for this under ``color``.
"""
- default_colour = Colour.default()
roles = self.roles[1:] # remove @everyone
# highest order of the colour is the one that gets rendered.
# if the highest is the default colour then the next one with a colour
# is chosen instead
- if roles:
- roles = sorted(roles, reverse=True)
- for role in roles:
- if role.colour == default_colour:
- continue
- else:
- return role.colour
-
- return default_colour
+ for role in reversed(roles):
+ if role.colour.value:
+ return role.colour
+ return Colour.default()
color = colour
@@ -314,11 +309,7 @@ class Member(discord.abc.Messageable, _BaseUser):
This is useful for figuring where a member stands in the role
hierarchy chain.
"""
-
- if self.roles:
- roles = sorted(self.roles, reverse=True)
- return roles[0]
- return None
+ return self.roles[-1]
@property
def guild_permissions(self):