I have a log channel set so if a user deletes a message, it gets sent to the channel so my moderators and myself can see deleted messages.
@client.event
async def on_message_delete(message):
if not message.author.bot:
embed = Embed(title = "[❌] A message has been deleted by a user.",
description = f"{message.author.display_name} (`{message.author.id}`) has deleted a message in the {message.channel.mention} channel.",
color = message.author.color,
timestamp = datetime.utcnow())
fields = [("Message:", message.content, False)]
for name, value, inline in fields:
embed.add_field(name=name, value=value, inline=inline)
embed.set_thumbnail(url = message.author.avatar_url)
embed.set_footer(text = "This message was deleted")
channel = client.get_channel(828362680452644904)
await channel.send(embed=embed)
I want to make it so this does not send an embed showcasing what my moderators or myself deleted to avoid clutter. Is there a way to do this?
Advertisement
Answer
You can just return if the message meets these conditions:
# get these values from your guild
MY_ID = 1234
MODERATOR_ROLE_ID = 56678
async def on_message_delete(message):
if message.author.id == MY_ID:
return
author_role_ids = [role.id for role in message.author.roles]
if MODERATOR_ROLE_ID in author_role_ids:
return
...