From 3346b28feee0f5900080ad026b369673e6f3c6a9 Mon Sep 17 00:00:00 2001 From: Rapptz Date: Sun, 23 Aug 2015 02:53:56 -0400 Subject: [PATCH] Add on_channel_delete event. --- discord/client.py | 10 ++++++++++ docs/api.rst | 7 +++++++ 2 files changed, 17 insertions(+) diff --git a/discord/client.py b/discord/client.py index e31c04f5c..ca5bd80d7 100644 --- a/discord/client.py +++ b/discord/client.py @@ -96,6 +96,8 @@ class Client(object): 'on_message_delete': _null_event, 'on_message_edit': _null_event, 'on_status': _null_event, + 'on_channel_delete': _null_event, + 'on_channel_creation': _null_event, } self.ws = WebSocketClient(endpoints.WEBSOCKET_HUB, protocols=['http-only', 'chat']) @@ -204,6 +206,14 @@ class Client(object): self._invoke_event('on_status', server, user, status, data.get('game_id')) elif event == 'USER_UPDATE': self.user = User(**data) + elif event == 'CHANNEL_DELETE': + guild_id = data.get('guild_id') + server = next((s for s in self.servers if s.id == guild_id), None) + if server is not None: + channel_id = data.get('id') + channel = next((c for c in server.channels if c.id == channel_id), None) + server.channels.remove(channel) + self._invoke_event('on_channel_delete', channel) diff --git a/docs/api.rst b/docs/api.rst index a161fe971..79a58cd82 100644 --- a/docs/api.rst +++ b/docs/api.rst @@ -63,6 +63,13 @@ All events are 'sandboxed', in that if an exception is thrown while the event is :param status: The new status of the user. :param game_id: The game ID that the user is playing. Can be None. +.. function:: on_channel_delete(channel) + + Called whenever a channel is removed from a server. + + Note that you can get the server from :attr:`Channel.server`. + + :param channel: The :class:`Channel` that got deleted. Data Classes --------------