Fix on_message_delete throwing error on attachments only
This commit is contained in:
parent
a9e6185b7e
commit
85082cbf16
2 changed files with 29 additions and 3 deletions
|
@ -25,7 +25,7 @@ jarvis = commands.Bot(
|
||||||
)
|
)
|
||||||
slash = SlashCommand(jarvis, sync_commands=True, sync_on_cog_reload=True)
|
slash = SlashCommand(jarvis, sync_commands=True, sync_on_cog_reload=True)
|
||||||
jarvis_self = Process()
|
jarvis_self = Process()
|
||||||
__version__ = "1.9.3"
|
__version__ = "1.9.4"
|
||||||
|
|
||||||
jconfig = get_config()
|
jconfig = get_config()
|
||||||
db = DBManager(jconfig.mongo["connect"]).mongo
|
db = DBManager(jconfig.mongo["connect"]).mongo
|
||||||
|
|
|
@ -55,7 +55,19 @@ class ModlogMessageCog(commands.Cog):
|
||||||
async def on_message_delete(self, message: discord.Message):
|
async def on_message_delete(self, message: discord.Message):
|
||||||
modlog = Setting.get(guild=message.guild.id, setting="modlog")
|
modlog = Setting.get(guild=message.guild.id, setting="modlog")
|
||||||
if 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)
|
channel = message.guild.get_channel(modlog.value)
|
||||||
embed = build_embed(
|
embed = build_embed(
|
||||||
title="Message Deleted",
|
title="Message Deleted",
|
||||||
|
@ -63,6 +75,15 @@ class ModlogMessageCog(commands.Cog):
|
||||||
fields=fields,
|
fields=fields,
|
||||||
color="#fc9e3f",
|
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(
|
embed.set_author(
|
||||||
name=message.author.name,
|
name=message.author.name,
|
||||||
icon_url=message.author.avatar_url,
|
icon_url=message.author.avatar_url,
|
||||||
|
@ -72,4 +93,9 @@ class ModlogMessageCog(commands.Cog):
|
||||||
text=f"{message.author.name}#{message.author.discriminator}"
|
text=f"{message.author.name}#{message.author.discriminator}"
|
||||||
+ f" | {message.author.id}"
|
+ 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)
|
||||||
|
)
|
||||||
|
|
Loading…
Add table
Reference in a new issue