diff options
| author | Rapptz <[email protected]> | 2017-03-23 19:34:36 -0400 |
|---|---|---|
| committer | Rapptz <[email protected]> | 2017-03-23 19:34:36 -0400 |
| commit | 9fcbe5c6789976afab0e6db959cb6e38d3f1f7c4 (patch) | |
| tree | f19b5e541a32ef087f88e70619a2fae84f29e3f4 | |
| parent | Upgrade aiohttp requirement to 2.0. (diff) | |
| download | discord.py-9fcbe5c6789976afab0e6db959cb6e38d3f1f7c4.tar.xz discord.py-9fcbe5c6789976afab0e6db959cb6e38d3f1f7c4.zip | |
Sort Guild.text_channels and Guild.voice_channels in UI order.
| -rw-r--r-- | discord/guild.py | 18 |
1 files changed, 14 insertions, 4 deletions
diff --git a/discord/guild.py b/discord/guild.py index 760632bc..021648d6 100644 --- a/discord/guild.py +++ b/discord/guild.py @@ -262,8 +262,13 @@ class Guild(Hashable): @property def voice_channels(self): - """List[:class:`VoiceChannel`]: A list of voice channels that belongs to this guild.""" - return [ch for ch in self._channels.values() if isinstance(ch, VoiceChannel)] + """List[:class:`VoiceChannel`]: A list of voice channels that belongs to this guild. + + 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) + return r @property def me(self): @@ -275,8 +280,13 @@ class Guild(Hashable): @property def text_channels(self): - """List[:class:`TextChannel`]: A list of text channels that belongs to this guild.""" - return [ch for ch in self._channels.values() if isinstance(ch, TextChannel)] + """List[:class:`TextChannel`]: A list of text channels that belongs to this guild. + + 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) + return r def get_channel(self, channel_id): """Returns a :class:`abc.GuildChannel` with the given ID. If not found, returns None.""" |