Home > Back-end >  How to add field to existing Embed (Discord.js v14)?
How to add field to existing Embed (Discord.js v14)?

Time:07-26

I get an embed out of a message and I want to add a field and then edit the message. Before I upgraded to v14, I could just do embed.addFields(). But now, when doing this, it just removes every property (color, description, etc.) from the embed, except for the field I add.

  let embed = new EmbedBuilder(msg.embeds[0])
  embed.addFields({name:'\u200B', value:`${emoji} ${role}`, inline:false})
  msg.edit({embeds: [embed]})
  msg.react(emoji);

I have also tried embed.fields.push(), but that also hasn't worked (the console says the function is undefined).

CodePudding user response:

Try EmbedBuilder.from(msg.embeds[0]) instead of new EmbedBuilder(msg.embeds[0])

CodePudding user response:

new EmbedBuilder() doesn't accept an Embed as the parameter. Use .data, .toJSON() or EmbedBuilder.from() (which does accept an Embed)

new EmbedBuilder(msg.embeds[0].data)
new EmbedBuilder(msg.embeds[0].toJSON())
EmbedBuilder.from(msg.embeds[0])

any of the lines above will work

  • Related