[英]Discord.py Deleted Messages not recovering photos
在我的 discord 機器人中,我有一個 function 收集已刪除的消息並將它們匯集到單獨服務器上的通道。 這非常適用於文本,但拒絕適用於圖像。 有沒有人有任何關於我如何讓它適用於圖像的提示?
這是我在活動中的內容:
@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")
嘗試使用.proxy_url
而不是.url
:
delete_embed.set_image(url=message.attachments[0].proxy_url)
Attachment.proxy_url
- “刪除郵件后,此 URL 可能在幾分鍾內有效或根本無效。”
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.