【问题标题】: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'

如何从嵌入中获取内容?

【问题讨论】:

  • 我认为错误不言自明,您无法获取不存在的消息
  • 以及如何从不存在的消息(嵌入)中获取内容?
  • 如果我之前的评论不够明显,你不能。除非它被机器人缓存

标签: python discord.py embed message


【解决方案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()

【讨论】:

  • 那我重启后无法从旧邮件中获取内容
猜你喜欢
  • 2020-09-05
  • 2021-12-13
  • 2021-05-24
  • 2021-06-12
  • 2015-02-18
  • 1970-01-01
  • 1970-01-01
  • 2019-12-27
  • 1970-01-01
相关资源
最近更新 更多