aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRapptz <[email protected]>2015-09-25 16:33:46 -0400
committerRapptz <[email protected]>2015-09-25 16:43:34 -0400
commit951dc922b012e159481ecd3ca14240fb5d04c113 (patch)
tree5b905a5c64fb8158b5802c568e5cc3d5b7924363
parentListen to CHANNEL_UPDATE events and add on_channel_update (diff)
downloaddiscord.py-951dc922b012e159481ecd3ca14240fb5d04c113.tar.xz
discord.py-951dc922b012e159481ecd3ca14240fb5d04c113.zip
Add edit_channel.
-rw-r--r--discord/client.py31
1 files changed, 31 insertions, 0 deletions
diff --git a/discord/client.py b/discord/client.py
index 50ded456..3aecba21 100644
--- a/discord/client.py
+++ b/discord/client.py
@@ -697,6 +697,37 @@ class Client(object):
else:
log.debug(request_logging_format.format(response=response, name='edit_profile'))
+ def edit_channel(self, channel, **options):
+ """Edits a :class:`Channel`.
+
+ You must have the proper permissions to edit the channel.
+
+ References pointed to the channel will be updated with the new information.
+
+ :param channel: The :class:`Channel` to update.
+ :param name: The new channel name.
+ :param position: The new channel's position in the GUI.
+ :param topic: The new channel's topic.
+ :returns: True if editing was successful, False otherwise.
+ """
+
+ url = '{0}/{1.id}'.format(endpoints.CHANNELS, channel)
+ payload = {
+ 'name': options.get('name', channel.name),
+ 'topic': options.get('topic', channel.topic),
+ 'position': options.get('position', channel.position)
+ }
+
+ response = requests.patch(url, headers=self.headers, json=payload)
+ if response.status_code == 200:
+ data = response.json()
+ log.debug(request_success_log.format(name='edit_channel', response=response, json=payload, data=data))
+ channel.update(server=channel.server, **data)
+ return True
+ else:
+ log.debug(request_logging_format.format(response=response, name='edit_channel'))
+ return False
+
def create_channel(self, server, name, type='text'):
"""Creates a :class:`Channel` in the specified :class:`Server`.