Reputation:
I'm trying to resend an embed from a message ID, this is my code
@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)
Whenever I run it, this error appears:
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'>
How can I get rid of that error?
Upvotes: 1
Views: 2258
Reputation: 1173
The problem is that you try to get an embed from an embed. Thus this line (which causes the error) should be removed: embed = discord.Embed.from_dict(embed)
.
The reason why the error occurs. Is that the embed object doesnt have an attribute 'get'. Which can be easily checked when looking at the documentation of the embed object, there is simply no attribute called "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)
Upvotes: 0
Reputation: 66
You are trying to create an embed from already existing embed. Remove
embed = discord.Embed.from_dict(embed)
and you will be fine
Upvotes: 1