aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRapptz <[email protected]>2017-09-21 00:11:36 -0400
committerRapptz <[email protected]>2017-09-21 00:11:36 -0400
commit95c28f08e49b1460ae9067dbc003c5206d62860f (patch)
tree748b51fc7e3d1f49bd498885074108c94d4fbfe9
parent[guild] use a defaultdict in by_category (diff)
downloaddiscord.py-95c28f08e49b1460ae9067dbc003c5206d62860f.tar.xz
discord.py-95c28f08e49b1460ae9067dbc003c5206d62860f.zip
Fix sorting for channels.
-rw-r--r--discord/guild.py10
1 files changed, 5 insertions, 5 deletions
diff --git a/discord/guild.py b/discord/guild.py
index bdb06403..1ab9cea0 100644
--- a/discord/guild.py
+++ b/discord/guild.py
@@ -283,7 +283,7 @@ class Guild(Hashable):
This is sorted by the position and are in UI order from top to bottom.
"""
r = [ch for ch in self._channels.values() if isinstance(ch, VoiceChannel)]
- r.sort(key=lambda c: c.position)
+ r.sort(key=lambda c: (c.position, c.id))
return r
@property
@@ -306,7 +306,7 @@ class Guild(Hashable):
This is sorted by the position and are in UI order from top to bottom.
"""
r = [ch for ch in self._channels.values() if isinstance(ch, TextChannel)]
- r.sort(key=lambda c: c.position)
+ r.sort(key=lambda c: (c.position, c.id))
return r
@property
@@ -316,7 +316,7 @@ class Guild(Hashable):
This is sorted by the position and are in UI order from top to bottom.
"""
r = [ch for ch in self._channels.values() if isinstance(ch, CategoryChannel)]
- r.sort(key=lambda c: c.position)
+ r.sort(key=lambda c: (c.position, c.id))
return r
def by_category(self):
@@ -341,13 +341,13 @@ class Guild(Hashable):
def key(t):
k, v = t
- return (k.position if k else -1, v)
+ return ((k.position, k.id) if k else (-1, -1), v)
_get = self._channels.get
as_list = [(_get(k), v) for k, v in grouped.items()]
as_list.sort(key=key)
for _, channels in as_list:
- channels.sort(key=lambda c: c.position)
+ channels.sort(key=lambda c: (c.position, c.id))
return as_list
def get_channel(self, channel_id):