aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRapptz <[email protected]>2015-10-16 15:52:11 -0400
committerRapptz <[email protected]>2015-10-16 15:52:11 -0400
commitbe14fd1dcc49b2806b3275b91cb74a8803de1c32 (patch)
tree358d9036dc3d9c46b65273fe4c94206be9ed5816
parentSeparate colour tuple into its own class. (diff)
downloaddiscord.py-be14fd1dcc49b2806b3275b91cb74a8803de1c32.tar.xz
discord.py-be14fd1dcc49b2806b3275b91cb74a8803de1c32.zip
Add Channel.voice_members
This allows you to see which members are currently in a voice channel.
-rw-r--r--discord/channel.py5
-rw-r--r--discord/server.py9
2 files changed, 14 insertions, 0 deletions
diff --git a/discord/channel.py b/discord/channel.py
index 74d74001..ee276f58 100644
--- a/discord/channel.py
+++ b/discord/channel.py
@@ -56,10 +56,15 @@ class Channel(object):
An array of :class:`Roles` that have been overridden from their default
values in the :attr:`Server.roles` attribute.
+ .. attribute:: voice_members
+
+ An array of :class:`Members` that are currently inside this voice channel.
+ If :attr:`type` is not ``'voice'`` then this is always an empty array.
"""
def __init__(self, **kwargs):
self.update(**kwargs)
+ self.voice_members = []
def update(self, **kwargs):
self.name = kwargs.get('name')
diff --git a/discord/server.py b/discord/server.py
index 0e596d44..62668bca 100644
--- a/discord/server.py
+++ b/discord/server.py
@@ -89,8 +89,17 @@ class Member(User):
self.is_afk = kwargs.get('suppress', False)
self.mute = kwargs.get('mute', False)
self.deaf = kwargs.get('deaf', False)
+ old_channel = getattr(self, 'voice_channel', None)
self.voice_channel = kwargs.get('voice_channel')
+ if old_channel is None and self.voice_channel is not None:
+ # we joined a channel
+ self.voice_channel.voice_members.append(self)
+ elif old_channel is not None and self.voice_channel is None:
+ # we left a channel
+ old_channel.voice_members.remove(self)
+
+
class Server(object):
"""Represents a Discord server.