首页 > 解决方案 > 我如何编辑和重新设计我的旧嵌入消息

问题描述

在嵌入之前,我在我的不和谐服务器上收到过一些短信。现在我只想编辑我的旧嵌入消息,通过重写一些东西和改变颜色来重新设计它的外观。如何通过消息 ID 编辑特定的嵌入消息?我知道它可以通过使用来编辑自己:

first_embed = Embed(title='embed 1')
new_embed = Embed(title='embed 2')

msg = await ctx.send(embed=first_embed)
await msg.edit(embed=new_embed)

但我真的不知道如何使它工作。它如何在消息 ID 处进行编辑?喜欢检查自己的身份证?

标签: discorddiscord.py

解决方案


您必须创建一个新命令来编辑嵌入并获取嵌入消息的 ID 以及您想要更改为参数的内容。然后您可以获取Embed.copy()Embed.to_dict()获取嵌入的数据,然后更新您作为参数获得的数据。

一个例子是:

@bot.command()
async def editembed(ctx, channel: discord.Chanel, msg_id, title, color):
    msg = await channel.fetch_message(msg_id)
    embed = msg.embeds[0].to_dict()
    embed["title"] = title
    embed["color"] = color
    await msg.edit(embed = discord.Embed.from_dict())

注意: 机器人没有获取消息属性,因此您必须从通道或上下文中获取它(使用上下文时,您必须在与要编辑的消息相同的通道上发送命令)


推荐阅读