From 794991adb6bfa6d66b2b977b1d2a6dcb639398d0 Mon Sep 17 00:00:00 2001 From: Rapptz Date: Fri, 21 Aug 2015 20:56:40 -0400 Subject: [PATCH] Add the ability to delete messages --- discord/client.py | 9 +++++++++ examples/deleted.py | 6 ++++++ 2 files changed, 15 insertions(+) diff --git a/discord/client.py b/discord/client.py index bd74ac29b..19b84b8b1 100644 --- a/discord/client.py +++ b/discord/client.py @@ -264,6 +264,15 @@ class Client(object): message = Message(channel=channel, **response.json()) return message + def delete_message(self, message): + """Deletes a :class:`Message` + + A fairly straightforward function. + + :param message: The :class:`Message` to delete. + """ + url = '{}/{}/messages/{}'.format(endpoints.CHANNELS, message.channel.id, message.id) + response = requests.delete(url, headers=self.headers) def login(self, email, password): """Logs in the user with the following credentials. diff --git a/examples/deleted.py b/examples/deleted.py index 611610133..7f77e9c38 100644 --- a/examples/deleted.py +++ b/examples/deleted.py @@ -9,6 +9,12 @@ def on_ready(): print('Username: ' + client.user.name) print('ID: ' + client.user.id) +@client.event +def on_message(message): + if message.content.startswith('!deleteme'): + msg = client.send_message(message.channel, 'I will delete myself now...') + client.delete_message(msg) + @client.event def on_message_delete(message): client.send_message(message.channel, '{} has deleted the message:\n{}'.format(message.author.name, message.content))