如何通过编辑从嵌入中删除字段?

How can I remove a field from an embed by editing it?

假设我创建了一个嵌入并将其发送到一个频道。这是嵌入:

const embed = new Discord.RichEmbed()
        .setColor(color)
        .setTitle(`${message.author.tag} wants to play.`)
        .setAuthor(message.author.tag, message.author.displayAvatarURL)
        .setDescription(game)
        .setThumbnail(icon)
        .addField(`\u200b\n**React with ${emoji} to join.**`, "Remove your reaction to leave.");

发送后,我想编辑该嵌入的标题和说明删除我在最后添加的字段。

这是我要创建的新嵌入:

const embed = new Discord.RichEmbed(reaction.message.embeds[0])
            .setTitle("This game has ended.")
            .setDescription("You can no longer join.");

这会更改标题和说明,但我不确定如何删除我也添加的字段。

对不起,我误会了。您可以手动将属性设置为 null,例如新嵌入对象的 embed.fields,here 是 RichEmbed 属性的文档。

在您的具体情况下,要删除所有字段,您可以这样做:

embed.fields = null;

我知道这是 6 个月大,但如果其他人像我一样在这里跌跌撞撞,你不应该将 embed.fields 设置为空。这可以防止以后使用 addField 方法添加新字段。而是将其设置为空数组。

embed.fields = [];

使用这个:

.spliceFields(startingIndex, numberOfFieldsToDelete, [
    {name: fieldName, value: fieldValue},
]);