Discord. Py Log Messages When Deleted
I Am Trying to Log Messages When They Were Deleted Using Print() Command. with My Poor Knowledge I Ended up with Something That Looks Like What Is Shown Below...
I am trying to log messages when they were deleted using print() command. With my poor knowledge I ended up with something that looks like what is shown below.
@bot.event
async def on_message_delete(message):
print(message.content + ": is deleted")
i want to print like "[username] deleted message in [channel] [Message]"
I would be appreciated if you add these features to work.
4 Answers
I found a way to check who deleted the message with the on_message_delete event, just use an audit_logs() with limit of one, like this:
async def on_message_delete(message):
async for entry in message.guild.audit_logs(limit=1,action=discord.AuditLogAction.message_delete):
deleter = entry.user
print(f"{deleter.name} deleted message by {message.author.name}")
The only problem I ran into was when someone deleted their own message, in which case it doesn't show up in the audit logs, so it gets flagged as someone else deleting it, I'm racking my brain, but no solutions come to mind. Enjoy!
It is indeed possible. I tried it myself, and i finally got it to work. Here's my code:
@client.event
async def on_message_delete(message):
msg = str(message.author)+ 'deleted message in '+str(message.channel)+': '+str(message.content)
print(msg)
If you want to make a snipe command, you'll want to store the deleted message in a variable. I used a dictionary to do this, where the key was the message.channel and the value was the msg. Hope this helps!
According to this tread it's (nowadays) not possible to find the name of the user that deleted a message, you can continue to search, this tread starts to be old, maybe this functionality has been added, but I can't find it, sorry...
@client.event
async def on_message_delete(message):
print(f'message: {message.content} by {message.author} was deleted in {message.channel}')
i cant figure out how to see the user that deleted the message but I don't it's that important, You need to see what the message was and who sent it and what channel it was sent in so you can punish accordingly!
Enjoy (this uses Discord.py ReWrite heads up)