mirror of
https://github.com/Rapptz/discord.py.git
synced 2025-06-08 04:38:42 +00:00
Add the ability to delete messages
This commit is contained in:
parent
35935b373b
commit
794991adb6
@ -264,6 +264,15 @@ class Client(object):
|
|||||||
message = Message(channel=channel, **response.json())
|
message = Message(channel=channel, **response.json())
|
||||||
return message
|
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):
|
def login(self, email, password):
|
||||||
"""Logs in the user with the following credentials.
|
"""Logs in the user with the following credentials.
|
||||||
|
@ -9,6 +9,12 @@ def on_ready():
|
|||||||
print('Username: ' + client.user.name)
|
print('Username: ' + client.user.name)
|
||||||
print('ID: ' + client.user.id)
|
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
|
@client.event
|
||||||
def on_message_delete(message):
|
def on_message_delete(message):
|
||||||
client.send_message(message.channel, '{} has deleted the message:\n{}'.format(message.author.name, message.content))
|
client.send_message(message.channel, '{} has deleted the message:\n{}'.format(message.author.name, message.content))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user