aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRapptz <[email protected]>2015-09-04 07:34:42 -0400
committerRapptz <[email protected]>2015-09-04 08:02:31 -0400
commit0e29d5a136c0cf9b5f43ac1fce2e3b1a2e921f7b (patch)
treea48fdddcbb3ff7c6aada1a6efae5805477bba572
parentAdd support for editing your profile. (diff)
downloaddiscord.py-0e29d5a136c0cf9b5f43ac1fce2e3b1a2e921f7b.tar.xz
discord.py-0e29d5a136c0cf9b5f43ac1fce2e3b1a2e921f7b.zip
Add the ability to create channels.
-rw-r--r--discord/client.py25
1 files changed, 25 insertions, 0 deletions
diff --git a/discord/client.py b/discord/client.py
index 33415d2b..1304f1b5 100644
--- a/discord/client.py
+++ b/discord/client.py
@@ -647,3 +647,28 @@ class Client(object):
self.headers['authorization'] = self.token
self.user = User(**data)
+ def create_channel(self, server, name, type='text'):
+ """Creates a :class:`Channel` in the specified :class:`Server`.
+
+ Note that you need the proper permissions to create the channel.
+
+ :param server: The :class:`Server` to create the channel in.
+ :param name: The channel's name.
+ :param type: The type of channel to create. 'text' or 'voice'.
+ :returns: The newly created :class:`Channel` if successful, else None.
+ """
+
+ payload = {
+ 'name': name,
+ 'type': type
+ }
+
+ url = '{0}/{1.id}/channels'.format(endpoints.SERVERS, server)
+ response = requests.post(url, headers=self.headers, json=payload)
+ if response.status_code in (200, 201):
+ data = response.json()
+ channel = Channel(server=server, **data)
+ # We don't append it to server.channels because CHANNEL_CREATE handles it for us.
+ return channel
+
+ return None