From 95c28f08e49b1460ae9067dbc003c5206d62860f Mon Sep 17 00:00:00 2001 From: Rapptz Date: Thu, 21 Sep 2017 00:11:36 -0400 Subject: [PATCH] Fix sorting for channels. --- discord/guild.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/discord/guild.py b/discord/guild.py index bdb064034..1ab9cea0e 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):