2
votes

I want to make my discord bot to send a reply message only if a user has deleted a message (not bots). I'm using message.author.bot to find out, but it seems that deleting messages isn't the same. So far I have this:

@client.event
async def on_message_delete(message):
  if message.author.bot:
    return
  await client.send_message(message.channel, "<@{}>'s message was deleted".format(message.author.id))
1
I'm unsure based on your wording whether you want to exclude messages of a bot that were deleted or messages that were deleted by a bot. Could you clarify your intentions?Minn
See this answer. Depending on your version, you may not be able to see who deleted a message.Patrick Haugh
@PatrickHaugh Thanks. It seems that the discord API doesn't show who deleted the message. Maybe this question is unsolvable.Cloud9c
Best you can do is give the bot permission to check the audit logs, then look for the message's deletion in there (as in that answer)Lynn

1 Answers

2
votes

Maybe this is the answer to your question

@client.event
async def on_message_delete(message, member):
    if message.author.id == client.user.id): #Checks the ID, if AuthorID = BotID, return. Else, continue.
        author : message.author #Defines the message author
        content : message.content #Defines the message content
        channel : message.channel #Defines the message channel
        logchannel = discord.utils.get(member.guild.channels, name='<XYZ>') #Defines the logs channel
        await logchannel.send(channel, '{}: {}'.format(author, content)) #Send the message.