【问题标题】:discord.py AttributeError: 'Embed' object has no attribute 'get'discord.py AttributeError:“嵌入”对象没有属性“获取”
【发布时间】:2020-08-07 02:58:13
【问题描述】:

我正在尝试从消息 ID 重新发送嵌入,这是我的代码

@commands.command()
async def test(self, ctx, messageID: int):
    channel = self.client.get_channel(740951313482907748)
    
    message = await channel.fetch_message(messageID)
    embed = message.embeds[0]
    embed = discord.Embed.from_dict(embed)
    await ctx.send(embed=embed)

每当我运行它时,就会出现这个错误:

Ignoring exception in command take:
Traceback (most recent call last):
  File "C:\Users\kwiecinski\AppData\Local\Programs\Python\Python38-32\lib\site-packages\discord\ext\commands\core.py", line 83, in wrapped
    ret = await coro(*args, **kwargs)
  File "C:\Users\kwiecinski\Desktop\test_bot\cogs\channels.py", line 61, in take
    embed = discord.Embed.from_dict(embedfrommessage)
  File "C:\Users\kwiecinski\AppData\Local\Programs\Python\Python38-32\lib\site-packages\discord\embeds.py", line 147, in from_dict
    self.title = data.get('title', EmptyEmbed)
AttributeError: 'Embed' object has no attribute 'get'
print(type(embed))
>>> <class 'discord.embeds.Embed'>

我怎样才能摆脱这个错误?

【问题讨论】:

    标签: python-3.x discord.py-rewrite


    【解决方案1】:

    您正在尝试从现有嵌入创建嵌入。 删除

    embed = discord.Embed.from_dict(embed)
    

    你会没事的

    【讨论】:

      【解决方案2】:

      问题是您尝试从嵌入中获取嵌入。因此应删除此行(导致错误):embed = discord.Embed.from_dict(embed)

      发生错误的原因。是embed object 没有属性'get'。查看embed object的文档可以很容易地检查到,根本没有称为“get”的属性。

      @commands.command()
      async def test(self, ctx, messageID: int):
          channel = self.client.get_channel(740951313482907748)
      
          message = await channel.fetch_message(messageID)
          embed = message.embeds[0] # this line returns an embed
          await ctx.send(embed=embed)
      

      【讨论】:

        猜你喜欢
        • 2021-05-06
        • 2021-04-13
        • 2021-05-22
        • 2019-05-23
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2021-08-19
        • 2021-05-16
        相关资源
        最近更新 更多