Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Deleting User Messages in Discord.py

Tags:

python

discord

Is there any way to delete a message sent by anyone other than the bot itself, the documentation seems to indicate that it is possible

Your own messages could be deleted without any proper permissions. However to delete other people’s messages, you need the proper permissions to do so.

But I can't find a way to target the message to do so in an on_message event trigger, am I missing something or is it just not possible?

like image 436
Hardline_98 Avatar asked Feb 11 '17 23:02

Hardline_98


People also ask

Can you delete all messages from a user on Discord?

Delete all messages in a Discord channel or DM Open DevTools pressing F12 or ⌘ command + option + J ; Copy the deleteDiscordMessages. js script and paste it in the Console, then press ENTER ; A window will be opened, fill the variables and click the START button.

How do you mass delete individual messages on Discord?

What is this? Open discord and double-click on the saved script to load it. Open the chat that you want to delete and press “T” on your keyboard. This will automatically start deleting the messages fast.


1 Answers

Yup, it should be possible.

You need the bot/user account to have the Manage Messages permission.

@client.event
async def on_message(message):
    await message.delete()

So, the event would occur something like

User sends message
Bot detects that the user has sent a message
Bot deletes the message that the user sent

Hopefully from this you should be able to see how user messages are deleted, just ensure that the bot/user account as the Manage Messages permission.

like image 182
ocelot Avatar answered Oct 07 '22 00:10

ocelot