In my discord bot, I have a function that collects deleted messages and funnels them to a channel on a separate server. This works perfectly for text but, refuses to work for images. Does anyone have any tips on how I could get this to work for images?
Here is what I have in my event:
@commands.Cog.listener()
async def on_message_delete(self, message):
#print(f"{message.author} deleted a message in #{message.channel}: {message.content}") #Tells the Console about the deleted message
if message.author == self.client.user:
return
elif message.author.bot == True:
return
now = datetime.now() #Grabs the current time
current_time=now.strftime("%H:%M:%S") #Formats the current time into a readable form.
current_date=now.strftime("%d/%m/%Y") #Formats the current date into a readable form.
delete_embed=discord.Embed(title = f"Message Deleted", description= f'**User:** <@{message.author.id}>
**Channel:** <#{message.channel.id}>
**Server:** {message.guild}
**Message:**
{message.content}', color=0xbf0404)
delete_embed.set_footer(text=f"Message ID: {message.id}
Date: {current_date} ? Time: {current_time}")
delete_embed.set_author(name =f"{message.author}", icon_url=f"{message.author.avatar_url}")
archive_delete=self.client.get_channel(789080972309168139) #Grabs the ID of the Deleted Messages Channel where the archive is to be stored.
try:
delete_embed.set_image(url=message.attachments[0].url)
except IndexError:
pass
await archive_delete.send(embed=delete_embed)
files=open("DeletedMessages.txt", "a") #Open the text file containing a backup of the deleted messages.
files.write(f"{message.author}'s message in #{message.channel} in {message.guild} was deleted at {current_time}: '{message.content}'
")
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…