Python Discord.py已删除的邮件未恢复照片

Python Discord.py已删除的邮件未恢复照片,python,discord,discord.py,Python,Discord,Discord.py,在我的discord机器人中,我有一个功能,可以收集已删除的消息,并将它们传送到单独服务器上的通道。这对文本非常有效,但对图像无效。有没有人能给我一些建议,告诉我如何让这个应用于图像 以下是我的活动: @commands.Cog.listener() async def on_message_delete(self, message): #print(f"{message.author} deleted a message in #{message.channel}: {mes

在我的discord机器人中,我有一个功能,可以收集已删除的消息,并将它们传送到单独服务器上的通道。这对文本非常有效,但对图像无效。有没有人能给我一些建议,告诉我如何让这个应用于图像

以下是我的活动:

@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}>\n**Channel:** <#{message.channel.id}>\n**Server:** {message.guild}\n**Message:** \n{message.content}', color=0xbf0404)
    delete_embed.set_footer(text=f"Message ID: {message.id}\nDate: {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}'\n")       
@commands.Cog.listener()
消息上的异步定义\u删除(self,message):
#print(f“{message.author}在{message.channel}:{message.content}中删除了一条消息”)#告诉控制台已删除的消息
如果message.author==self.client.user:
返回
elif message.author.bot==True:
返回
now=datetime.now()#获取当前时间
当前时间=现在。strftime(“%H:%M:%S”)#将当前时间格式化为可读形式。
current_date=now.strftime(“%d/%m/%Y”)#将当前日期格式化为可读形式。
delete_embed=discord.embed(title=f“Message Deleted”,description=f'**User:*\n**Channel:*\n**Server:*{Message.guild}\n**Message:*\n{Message.content},color=0xbf0404)
删除\u embed.set\u页脚(text=f“消息ID:{Message.ID}\n日期:{current\u date}•Time:{current\u Time}”)
删除\u embed.set\u author(name=f“{message.author}”,icon\u url=f“{message.author.avatar\u url}”)
archive_delete=self.client.get_channel(789080972309168139)#获取存储存档的已删除消息通道的ID。
尝试:
删除嵌入。设置图像(url=message.attachments[0]。url)
除索引器外:
通过
等待存档\u删除.send(嵌入=删除\u嵌入)
files=open(“DeletedMessages.txt”,“a”)#打开包含已删除邮件备份的文本文件。
files.write(f“{message.author}在{message.guild}中的{message.channel}中的{message.author}消息在{current_time}被删除:{message.content}'\n”)

尝试使用
.proxy\u url
而不是
.url

delete_embed.set_image(url=message.attachments[0].proxy_url)

参考资料:
  • -“删除邮件时,此URL可能在几分钟内有效或根本无效。”

这是唯一的可能,否则您需要自己归档邮件的图像。