【问题标题】:Discord.py Deleted Messages not recovering photosDiscord.py 已删除邮件无法恢复照片
【发布时间】:2020-12-31 22:13:37
【问题描述】:

在我的 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")       

【问题讨论】:

    标签: python discord discord.py


    【解决方案1】:

    尝试使用.proxy_url 而不是.url

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

    参考资料:

    • Attachment.proxy_url - “删除邮件后,此 URL 可能在几分钟内有效或根本无效。”

    【讨论】:

    • 这是唯一真正的可能性,否则您需要自己存档消息的图像。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-07-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-09-21
    • 2013-06-27
    • 2014-06-11
    相关资源
    最近更新 更多