From 85082cbf16ac707b8ee5d62401f86c80609fda50 Mon Sep 17 00:00:00 2001 From: Zevaryx Date: Mon, 2 Aug 2021 23:50:50 -0600 Subject: [PATCH] Fix on_message_delete throwing error on attachments only --- jarvis/__init__.py | 2 +- jarvis/cogs/modlog/message.py | 30 ++++++++++++++++++++++++++++-- 2 files changed, 29 insertions(+), 3 deletions(-) diff --git a/jarvis/__init__.py b/jarvis/__init__.py index 185f94d..661dc8e 100644 --- a/jarvis/__init__.py +++ b/jarvis/__init__.py @@ -25,7 +25,7 @@ jarvis = commands.Bot( ) slash = SlashCommand(jarvis, sync_commands=True, sync_on_cog_reload=True) jarvis_self = Process() -__version__ = "1.9.3" +__version__ = "1.9.4" jconfig = get_config() db = DBManager(jconfig.mongo["connect"]).mongo diff --git a/jarvis/cogs/modlog/message.py b/jarvis/cogs/modlog/message.py index 0cc130f..c6cc3e6 100644 --- a/jarvis/cogs/modlog/message.py +++ b/jarvis/cogs/modlog/message.py @@ -55,7 +55,19 @@ class ModlogMessageCog(commands.Cog): async def on_message_delete(self, message: discord.Message): modlog = Setting.get(guild=message.guild.id, setting="modlog") if modlog: - fields = [Field("Original Message", message.content, False)] + fields = [ + Field("Original Message", message.content or "N/A", False) + ] + + if message.attachments: + fields.append( + Field( + name="Attachments", + value=f"{len(message.attachments)}", + inline=False, + ) + ) + channel = message.guild.get_channel(modlog.value) embed = build_embed( title="Message Deleted", @@ -63,6 +75,15 @@ class ModlogMessageCog(commands.Cog): fields=fields, color="#fc9e3f", ) + + add_file = False + if ( + message.attachments + and "image" in message.attachments[0].content_type + ): + embed.set_image(url=message.attachments[0].url) + elif message.attachments: + add_file = True embed.set_author( name=message.author.name, icon_url=message.author.avatar_url, @@ -72,4 +93,9 @@ class ModlogMessageCog(commands.Cog): text=f"{message.author.name}#{message.author.discriminator}" + f" | {message.author.id}" ) - await channel.send(embed=embed) + if add_file: + await channel.send(embed=embed) + else: + await channel.send( + embed=embed, file=(await message.attachments[0].to_file) + )