From 49b9b987c771185b71c93e6f87bdce05ab0d55dc Mon Sep 17 00:00:00 2001 From: Rapptz Date: Mon, 24 Aug 2015 00:11:29 -0400 Subject: [PATCH] Add support for creating or deleting channels from the client. --- discord/client.py | 33 +++++++++++++++++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-) diff --git a/discord/client.py b/discord/client.py index 076c8c367..9fbfd1788 100644 --- a/discord/client.py +++ b/discord/client.py @@ -367,7 +367,6 @@ class Client(object): data = response.json() return Message(channel=channel, **data) - def login(self, email, password): """Logs in the user with the following credentials and initialises the connection to Discord. @@ -417,7 +416,6 @@ class Client(object): self._is_logged_in = False self.keep_alive.cancel() - def logs_from(self, channel, limit=500): """A generator that obtains logs from a specified channel. @@ -463,3 +461,34 @@ class Client(object): self.events[function.__name__] = function return function + def create_channel(self, server, name, type='text'): + """Creates a channel in the specified server. + + In order to create the channel the client must have the proper permissions. + + :param server: The :class:`Server` to create the channel from. + :param name: The name of the channel to create. + :param type: The type of channel to create. Valid values are 'text' or 'voice'. + :returns: The recently created :class:`Channel`. + """ + url = '{}/{}/channels'.format(endpoints.SERVERS, server.id) + payload = { + 'name': name, + 'type': type + } + response = requests.post(url, json=payload, headers=self.headers) + if response.status_code == 200: + channel = Channel(server=server, **response.json()) + return channel + + def delete_channel(self, channel): + """Deletes a channel. + + In order to delete the channel, the client must have the proper permissions + in the server the channel belongs to. + + :param channel: The :class:`Channel` to delete. + """ + url = '{}/{}'.format(endpoints.CHANNELS, channel.id) + response = requests.delete(url, headers=self.headers) +