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.
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.
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 theto_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.