aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRapptz <[email protected]>2015-08-24 00:11:29 -0400
committerRapptz <[email protected]>2015-08-24 00:11:29 -0400
commit49b9b987c771185b71c93e6f87bdce05ab0d55dc (patch)
tree1fb2565f3cd45980f9339cb5c7c8545110521977
parentAdd logout support and on_disconnect event. (diff)
downloaddiscord.py-49b9b987c771185b71c93e6f87bdce05ab0d55dc.tar.xz
discord.py-49b9b987c771185b71c93e6f87bdce05ab0d55dc.zip
Add support for creating or deleting channels from the client.
-rw-r--r--discord/client.py33
1 files changed, 31 insertions, 2 deletions
diff --git a/discord/client.py b/discord/client.py
index 076c8c36..9fbfd178 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)
+