Home > Mobile >  Copy embed and modify between chats discordjs
Copy embed and modify between chats discordjs

Time:11-12

I'm trying to change some information on embed messages then transfer the message from channels, but when I try to transfer the message, I have this error:

RangeError [EMBED_FIELD_NAME]: MessageEmbed field names must be non-empty strings.

I've trying like this:

let title;
let fieldName;
let fieldValue;

if(message.channel.id == analiseChannelID && reaction.emoji.name === 'aprovada') {
  message.embeds.forEach(embeds => {
    let title = embeds.title;
    //console.log(embeds.title); // logging to console ✅
    let fields = embeds.fields;
    fields.forEach((field) => {
      //console.log(field.name); // logging to console ✅
      //console.log(field.value); // logging to console ✅
      fieldName = field.name;
      fieldValue = field.value;
    });
    let embed1 = new Discord.MessageEmbed().addFields(fieldName, fieldValue)
    ChannelAprovada.send(embed1)
  })
}

CodePudding user response:

You used the MessageEmbed#addFields method (with an s) which requires objects as arguments. Changing it to MessageEmbed#addField should work

let embed1 = new Discord.MessageEmbed()
                .addField(fieldName, fieldValue) //no "s"

CodePudding user response:

As @MrMythical said, changing MessageEmbed#addFields to MessageEmbed#addField should help you, but instead of .addField(fieldName, fieldValue) try to use .addField(fieldName, `** ** ${fieldValue}`)! Using ** ** should help you prevent getting an error even if your fieldValue is empty for some reason!

Also in discord.js v13 you have to use ChannelAprovada.send({embeds: [embed1]}) instead of ChannelAprovada.send(embed1) to send an embed!

CodePudding user response:

Try another.

.addFields({ name: `text`, value: `text`})

For discord v.13

.addField("text", "text")
  • Related