aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRapptz <[email protected]>2015-09-25 16:09:10 -0400
committerRapptz <[email protected]>2015-09-25 16:09:10 -0400
commit120b9cd3b2ade2ace73cb926b8dca7297329f10f (patch)
tree541e8fd6cb7bd94c09f41da7f411194a3add0790
parentAdd support for channel topics. (diff)
downloaddiscord.py-120b9cd3b2ade2ace73cb926b8dca7297329f10f.tar.xz
discord.py-120b9cd3b2ade2ace73cb926b8dca7297329f10f.zip
Listen to CHANNEL_UPDATE events and add on_channel_update
-rw-r--r--discord/channel.py3
-rw-r--r--discord/client.py8
-rw-r--r--docs/api.rst6
3 files changed, 17 insertions, 0 deletions
diff --git a/discord/channel.py b/discord/channel.py
index a3e433e0..74d74001 100644
--- a/discord/channel.py
+++ b/discord/channel.py
@@ -59,6 +59,9 @@ class Channel(object):
"""
def __init__(self, **kwargs):
+ self.update(**kwargs)
+
+ def update(self, **kwargs):
self.name = kwargs.get('name')
self.server = kwargs.get('server')
self.id = kwargs.get('id')
diff --git a/discord/client.py b/discord/client.py
index 2df742f5..50ded456 100644
--- a/discord/client.py
+++ b/discord/client.py
@@ -114,6 +114,7 @@ class Client(object):
'on_status': _null_event,
'on_channel_delete': _null_event,
'on_channel_create': _null_event,
+ 'on_channel_update': _null_event,
'on_member_join': _null_event,
'on_member_remove': _null_event,
'on_member_update': _null_event,
@@ -265,6 +266,13 @@ class Client(object):
channel = utils.find(lambda c: c.id == channel_id, server.channels)
server.channels.remove(channel)
self._invoke_event('on_channel_delete', channel)
+ elif event == 'CHANNEL_UPDATE':
+ server = self._get_server(data.get('guild_id'))
+ if server is not None:
+ channel_id = data.get('id')
+ channel = utils.find(lambda c: c.id == channel_id, server.channels)
+ channel.update(server=server, **data)
+ self._invoke_event('on_channel_update', channel)
elif event == 'CHANNEL_CREATE':
is_private = data.get('is_private', False)
channel = None
diff --git a/docs/api.rst b/docs/api.rst
index ccd27f2e..ef3247fc 100644
--- a/docs/api.rst
+++ b/docs/api.rst
@@ -86,6 +86,12 @@ All events are 'sandboxed', in that if an exception is thrown while the event is
:param channel: The :class:`Channel` that got added or deleted.
+.. function:: on_channel_update(channel)
+
+ Called whenever a channel is updated. e.g. changed name, topic, permissions.
+
+ :param channel: The :class:`Channel` that got updated.
+
.. function:: on_member_join(member)
on_member_remove(member)