Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/algorithm/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何通过编辑从嵌入中删除字段?_Javascript_Discord_Discord.js - Fatal编程技术网

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

Javascript 如何通过编辑从嵌入中删除字段?,javascript,discord,discord.js,Javascript,Discord,Discord.js,假设我创建了一个嵌入并将其发送到一个通道。以下是我们的建议: const embed = new Discord.RichEmbed() .setColor(color) .setTitle(`${message.author.tag} wants to play.`) .setAuthor(message.author.tag, message.author.displayAvatarURL) .setDescription(ga

假设我创建了一个嵌入并将其发送到一个通道。以下是我们的建议:

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.");

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

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

在您的特定情况下,要删除所有字段,可以执行以下操作:

embed.fields = null;

我知道这是6个月前的事了,但如果有人像我一样在这里绊倒了,你不应该将embed.fields设置为null。这将防止以后使用addField方法添加新字段。而是将其设置为空数组

embed.fields = [];
使用以下命令:

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

哦,很抱歉没有指定我需要保持作者、颜色和缩略图相同,因此我必须从上一个创建嵌入。将此作为解决方案,希望我在6个月前就知道这一点:(