编辑 discord.py 嵌入,就好像有人在上面嵌入了 "commented"

edit a discord.py embed as if someone has "commented" on it

我有一个命令可以根据用户的消息发送嵌入...我希望能够像评论一样使用命令向嵌入消息添加内容。这是 Discord 制作的机器人的示例:

正如您在图片中看到的那样,人们已经对嵌入发表了评论。我希望能够做到这一点:保留原始内容,使用命令添加更多内容。
我知道如何编辑消息,但我找不到任何有关在特定嵌入字段中添加内容的信息。

一些示例代码,以便您了解我的思维过程:

@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)

请不要回答告诉我为什么这段代码不起作用我知道为什么这只是一个例子,这样更容易理解我的思维过程。

这很简单,您可以使用 Embed.to_dict 将嵌入转换为字典,然后像使用普通 python 字典一样使用它。然后将其转换回 discord.Embed 实例使用 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)

参考:

谢谢。我成功地使用了 message.embeds 并且效果惊人。

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)