diff --git a/discord/client.py b/discord/client.py index ca5bd80d7..714fd0455 100644 --- a/discord/client.py +++ b/discord/client.py @@ -97,7 +97,7 @@ class Client(object): 'on_message_edit': _null_event, 'on_status': _null_event, 'on_channel_delete': _null_event, - 'on_channel_creation': _null_event, + 'on_channel_create': _null_event, } self.ws = WebSocketClient(endpoints.WEBSOCKET_HUB, protocols=['http-only', 'chat']) @@ -214,8 +214,22 @@ class Client(object): 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) + elif event == 'CHANNEL_CREATE': + is_private = data.get('is_private', False) + channel = None + if is_private: + recipient = User(**data.get('recipient')) + pm_id = data.get('id') + channel = PrivateChannel(id=pm_id, user=recipient) + self.private_channels.append(channel) + else: + 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 = Channel(server=server, **data) + server.channels.append(channel) - + self._invoke_event('on_channel_create', channel) def _opened(self): print('Opened at {}'.format(int(time.time()))) diff --git a/docs/api.rst b/docs/api.rst index 79a58cd82..9909bcd17 100644 --- a/docs/api.rst +++ b/docs/api.rst @@ -64,12 +64,15 @@ All events are 'sandboxed', in that if an exception is thrown while the event is :param game_id: The game ID that the user is playing. Can be None. .. function:: on_channel_delete(channel) + on_channel_create(channel) - Called whenever a channel is removed from a server. + Called whenever a channel is removed or added from a server. Note that you can get the server from :attr:`Channel.server`. + :func:`on_channel_create` could also pass in a :class:`PrivateChannel` depending + on the value of :attr:`Channel.is_private`. - :param channel: The :class:`Channel` that got deleted. + :param channel: The :class:`Channel` that got added or deleted. Data Classes -------------- diff --git a/setup.py b/setup.py index 20245d043..a76f466f1 100644 --- a/setup.py +++ b/setup.py @@ -1,9 +1,10 @@ from setuptools import setup import re -requirements = '' -with open('requirements.txt') as f: - requirements = f.read().splitlines() +requirements = [ + 'ws4py', + 'requests' +] version = '' with open('discord/__init__.py') as f: