Discord.js Avatar命令无法提及用户

时间:2020-06-29 05:45:31

标签: javascript discord

如果我检查自己的头像,我的代码可以正常工作,但是当我提到用户时,代码无法正常工作

这是我的代码:

client.on('message', message => {
  if (message.content === `${prefix}ava`) {
    const taggedUser = message.mentions.users.first() || message.author;
    const avatarEmbed = new Discord.RichEmbed()
        .setColor(0xFFC0CB)
        .setAuthor(`${taggedUser.tag} - ${taggedUser.presence.status}`)
        .setImage(taggedUser.avatarURL({ format: "png", dynamic: true, size: 1024 }));
    message.channel.send(avatarEmbed);
  }
});

1 个答案:

答案 0 :(得分:0)

尝试使用displayAvatarURL

您还应该检查message.mentions.users.size是否包含提及:

  const embed = new Discord.RichEmbed()
    .setColor(0xFFC0CB)
    .setImage(`${message.author.displayAvatarURL}`)
    .addField('Your avatar:', `[Image URL](${message.author.displayAvatarURL})`, true)

  if (!message.mentions.users.size) {
    return message.channel.send(embed)
  }

  const user = message.mentions.users.first() || message.author
  const embed2 = new Discord.RichEmbed()
    .setColor(0xFFC0CB)
    .setImage(`${user.displayAvatarURL}`)
    .setThumbnail(`${user.displayAvatarURL}`)
    .addField(`${user.username}'s avatar:`, `${user.displayAvatarURL}`, true)

  message.channel.send(embed2)