Ivynl
Ivynl

Reputation: 17

addfields is not defined

I am trying to make a Discord Bot. Now I am working on embeds and I am trying to do 'userinfo' embed. When I use { name: 'Nickname', value: message.member.nickname } this line it only prints the nickname. Which means if a user don't has a nickname in server the code writes null to nickname part. So I wrote a code and it gave and error.

The error is:

ReferenceError: addfields is not defined this.

And this is the code:

case 'userinfov2':
  const userinfov2 = new Discord.MessageEmbed()
    .setTitle('Userinfo')
    .setColor('#F4F869')
    .setThumbnail(message.author.avatarURL())
  if (message.member.nickname) {
    addfields(
      {
        name: 'Nickname',
        value: message.member.nickname
      }
    )
  } else {
    addfields(
      {
        name: 'Nickname',
        value: message.member.displayName
      }
    )
  }
  message.channel.send(userinfov2);
  break;

Upvotes: 0

Views: 277

Answers (1)

Zer0
Zer0

Reputation: 1690

You are missing a reference to the Object where you want to add the fields, try:

const userinfov2 = new Discord.MessageEmbed()
    .setTitle('Userinfo')
    .setColor('#F4F869')
    .setThumbnail(message.author.avatarURL());
if (message.member.nickname) {
    userinfov2.addFields(
        { name: 'Nickname', value: message.member.nickname }
    );
} else {
    userinfov2.addFields(
        { name: 'Nickname', value: message.member.displayName }
    );
}

message.channel.send(userinfov2);

Upvotes: 2

Related Questions