如何从已删除的消息中获取嵌入内容?
Posted
技术标签:
【中文标题】如何从已删除的消息中获取嵌入内容?【英文标题】:How to get embed content from a deleted message? 【发布时间】:2021-07-03 02:51:47 【问题描述】: @commands.Cog.listener()
async def on_raw_message_delete(self, payload):
try:
conn.reconnect()
except:
pass
print("deleted")
channel=self.client.get_channel(payload.channel_id)
message=await channel.fetch_message(payload.message_id) #<===========
emb=message.embeds
for mes in emb:
cursor.execute(f"DELETE FROM suggestions WHERE channel_id=payload.channel_id and id=payload.guild_id and code=mes.fields[1].value")
conn.commit()
discord.errors.NotFound: 404 Not Found (error code:10008): Unknown message
当我将代码更改为此时,它显示了另一个错误
@commands.Cog.listener()
async def on_raw_message_delete(self, payload):
try:
conn.reconnect()
except:
pass
print("deleted")
channel=self.client.get_channel(payload.channel_id)
message=payload.cached_message
emb=message.embeds #<===========
for mes in emb:
cursor.execute(f"DELETE FROM suggestions WHERE channel_id=payload.channel_id and id=payload.guild_id and code=mes.fields[1].value")
conn.commit()
AttributeError: 'NoneType' 对象没有属性 'embeds'
如何从嵌入中获取内容?
【问题讨论】:
我认为错误不言自明,您无法获取不存在的消息 以及如何从不存在的消息(嵌入)中获取内容? 如果我之前的评论不够明显,你不能。除非它被机器人缓存 【参考方案1】:如果你想从消息中嵌入,你可以使用on_message_delete
事件,因为它给你消息对象,像这样:
async def on_message_delete(message): # Event that triggers every time a message is deleted
try:
conn.reconnect()
except:
pass
print("Deleted")
emb = message.embeds
for mes in emb:
cursor.execute(f"DELETE FROM suggestions WHERE channel_id=message.channel.id and id=message.guild.id and code=mes.fields[1].value")
conn.commit()
【讨论】:
那我重启后无法从旧邮件中获取内容以上是关于如何从已删除的消息中获取嵌入内容?的主要内容,如果未能解决你的问题,请参考以下文章