discord.py AttributeError: 'Embed' object has no attribute 'get'
discord.py AttributeError: 'Embed' object has no attribute 'get'
我正在尝试从消息 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'>
我怎样才能摆脱这个错误?
您正在尝试从现有嵌入创建嵌入。
移除
embed = discord.Embed.from_dict(embed)
你会没事的
问题是您试图从嵌入中获取嵌入。因此这一行(导致错误)应该被删除:embed = discord.Embed.from_dict(embed)
.
错误发生的原因。就是那个embed object doesnt have an attribute 'get'. Which can be easily checked when looking at the documentation of the 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)
我正在尝试从消息 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'>
我怎样才能摆脱这个错误?
您正在尝试从现有嵌入创建嵌入。 移除
embed = discord.Embed.from_dict(embed)
你会没事的
问题是您试图从嵌入中获取嵌入。因此这一行(导致错误)应该被删除:embed = discord.Embed.from_dict(embed)
.
错误发生的原因。就是那个embed object doesnt have an attribute 'get'. Which can be easily checked when looking at the documentation of the 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)