3
votes

I have a command that sends an embed based on a user's message... I want to be able to add content to the embed message with a command as if I were commenting. Here's an example from a bot made by Discord:

embed "can reproduce" field has comments

As you can see in the image people have left comments on the embed. I want to be able to do exactly that: keep original content, add more content with a command.
I know how to edit messages but I cannot find anything about adding content in a specific embed field.

Some example code so you can understand my thought process:

@client.command()
async def comment(ctx, message, *, args):
    messagec = await ctx.fetch_message(message)
    embed = discord.Embed(title=messagec.content['title'], description=messagec.content['description'])
    value = f'\n`{ctx.message.author.name}: {args}`'
    embed.add_value(name='comments', value=value)
    await message.edit(embed=embed)

Please don't respond telling me why this code won't work I know why this is just an example so it's easier to understand my thought process.

2

2 Answers

2
votes

It's pretty simple, you can convert the embed to a dictionary with Embed.to_dict and then work with it like with a normal python dict. Then to convert it back to a discord.Embed instance use the Embed.from_dict classmethod

embed_dict = embed.to_dict()

for field in embed_dict["fields"]:
    if field["name"] == "your field name here":
        field["value"] += "new comment!"

embed = discord.Embed.from_dict(embed_dict)
await message.edit(embed=embed)

Reference:

0
votes

thanks. i managed to use message.embeds and it worked amazing.

embed = message.embeds[0]
embed_dict = embed.to_dict()

for field in embed_dict["fields"]:
    if field["name"] == "your field name here":
        field["value"] += "new comment!"

embed = discord.Embed.from_dict(embed_dict)
await message.edit(embed=embed)