So i just made a event both for on_message_delete
and on_message_edit
second one works as intended but for first one, i want to make it like Quark Logger; if message deleted by author, no one will mentioned and when message deleted by someone else, it’ll add a field to embed that includes the person who did the action.
here’s my approach:
@commands.Cog.listener()
async def on_message_delete(self, message : discord.Message):
async for entry in message.guild.audit_logs(limit=1,action=discord.AuditLogAction.message_delete):
deletedBy = entry.user
logtime = entry.created_at.strftime("%d-%m-%Y %H:%M")
lcltime = datetime.datetime.now(timezone("UTC")).strftime("%d-%m-%Y %H:%M")
if logtime == lcltime and deletedBy != message.author: not_self_delete = True
else: self_delete = False
if message.channel.type != discord.ChannelType.private:
if hasattr(message.author, "guild") and message.guild.id == IEEM:
channel1=self.bot.get_channel(my_log_chan)
channel2=self.bot.get_channel(another_log_chan_in_diff_server)
embed=discord.Embed(title=f"{message.author.name} deleted a message.", description=f"Content: {message.content} n Channel: {message.channel.mention}", color=0xFF5733)
embed.set_author(name=self.bot.user.name, icon_url=self.bot.user.display_avatar)
if not_self_delete: embed.set_footer(text=f"Message deleted at: {localtime} nMessage deleted by: {deleter.name}")
else: embed.set_footer(text=f"Message deleted at: {localtime}")
attachmentFiles=[]
for index, attach in enumerate(message.attachments):
embed2.add_field(name=f"Attachment {index+1}", value=f"[{attach.filename}]({attach.url})")
attachmentFile = await attach.to_file()
attachmentFiles.append(attachmentFile)
if not message.author.bot:
await channel1.send(embed=embed, files=attachmentFiles)
await channel2.send(embed=embed, files=attachmentFiles)
At first, it worked as i wanted but when a minute or so goes code just breaks and always returns “False” and strangely, when I delete somebodys message and they delete their own another message just in time, my variable becomes “True” and two embeds will say message deleted by Me in reality i deleted only one message.