Discord.py: Dictionary to embed

Created on 7 Jun 2018  路  3Comments  路  Source: Rapptz/discord.py

I'm new to programming and i wonder if it's possible to feed the embed class with a dictionary.

Instead of doing something like this:

em = discord.Embed(title="myTitle", description="myDescription")

or like this:

em = discord.Embed()
em.title = myVariable.get("myTitle")
em.description = myVariable.get("myDescription")

to do something like this. Letting the existing class to do all the work.

myDict = {"title":  "myTitle", "description":  "myDescription"}
em = discord.Embed(myDict) 
yield from client.send_message(message.channel, embed=em)

I tried a few things but it didn't worked. Now i'm thinking to iterate over the dictionary key, values and feed the class, this or re-implement my own class which might be a pain to do it using my limited knowledge.
Any tips would help greatly.

Most helpful comment

@mrc0mmand's answer is only partially correct- while that works for top-level stuff like color, description, etc, it won't work for fields, the author, or the image. To do this, instead use
embed.from_data(some_dict)- to see how these dicts are setup, create an embed object manually and use the to_dict() method.

Furthermore, similar questions are better suited to the d.py discord server as the github issues are more for, yknow, actual issues with the lib.

All 3 comments

Well, your second third snippet is almost correct, just use **myDict:

myDict = {"title":  "myTitle", "description":  "myDescription"}
em = discord.Embed(**myDict) 
yield from client.send_message(message.channel, embed=em)

@mrc0mmand's answer is only partially correct- while that works for top-level stuff like color, description, etc, it won't work for fields, the author, or the image. To do this, instead use
embed.from_data(some_dict)- to see how these dicts are setup, create an embed object manually and use the to_dict() method.

Furthermore, similar questions are better suited to the d.py discord server as the github issues are more for, yknow, actual issues with the lib.

Thank you very much guys, i wasted 4 hours looking for a solution and your input was really helpful.
Sorry for posting the question here, didn't know about the discord server.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Yolotroll101 picture Yolotroll101  路  3Comments

Rimmy50 picture Rimmy50  路  3Comments

PicklesJars picture PicklesJars  路  3Comments

synbitz picture synbitz  路  3Comments

adhoc92 picture adhoc92  路  3Comments