M
M
Mem13882021-06-04 21:35:24
Python
Mem1388, 2021-06-04 21:35:24

How to build an Embed from JSON data?

I'm trying to make a command that will accept JSON data, and build Embed from them.
Let's say a person sends a string like this:

{"plainText": "Testing", "fields": [{"name": "Test-1", "value": "Value-1", "inline": false}, {"name": "Test-2", "value": "Value-2", "inline": true}], "color": 0}

And Embed should go:
emb = discord.Embed(color = 0x00000)
emb.add_field(name = "Test-1", value = "Value-1", inline = False)
emb.add_field(name = "Test-2", value = "Value-2", inline = True)
await ctx.send(plainText, embed = emb)

How can this be checked?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
R
retUrn3d, 2021-06-05
@Mem1388

Use the method from_dict()
Read more here

emb_json = json.load(embed_file)
emb = discord.Embed.from_dict(emb_json)
        await ctx.send(embed=emb)

D
Dream, 2021-06-04
@dreameddd

You take the necessary data from JSON data and substitute it in emb.
test1 = ... (take data value-1)
As a result, to get:

emb.add_failed(name = "Test-1", value = test1, inline = False)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question