用户信息命令仅在没有提及的情况下起作用

user info command works only witout a mention

我的命令 userinfo 的代码有问题,它可以在没有命令的情况下工作,但没有提到 somoen

wenn 我 运行 没有提及的代码有效,但我尝试与用户一起测试它提到的代码 dosent 给我一个错误它只是忽略它

这是代码

  if (message.content === prefix + 'userinfo') {
    if (message.mentions.users.size) {
      const embed = new MessageEmbed()
        .setTitle(`${message.mentions.users.first().tag}`)
        .setColor("03fc94")
        .setThumbnail(message.mentions.users.first().avatarURL())
        .addFields(
          { name: 'ID', value: `${message.mentions.users.first().id}`, inline: true }, 
          { name: 'Username', value: `${message.mentions.users.first().username}`, inline: true },
          { name: 'Discriminator', value: `${message.mentions.users.first().discriminator}`, inline: true },
          { name: 'Bot', value: `${message.mentions.users.first().bot}`, inline: true },
          { name: 'Created At', value: `${message.mentions.users.first().createdAt}`, inline: true },
          { name: 'Roles', value: `${message.mentions.users.first().roles.cache.map(r => r.name).join(', ')}`, inline: true },
        )
        .setTimestamp()
        .setFooter('');
        message.channel.send({ embeds: [embed]});
    } else {
      const embed = new MessageEmbed()
        .setTitle(`${message.author.tag}`)
        .setColor("03fc94")
        .setThumbnail(message.author.avatarURL())
        .addFields(
          { name: 'ID', value: `${message.author.id}`, inline: true },
          { name: 'Discriminator', value: `${message.author.discriminator}`, inline: true },
          { name: 'roles', value: `${message.member.roles.cache.map(r => r.name).join(', ')}`, inline: true },
          { name: 'Joined', value: `${message.member.joinedAt}`, inline: true },
          { name: 'Created', value: `${message.author.createdAt}`, inline: true },
          { name: 'Is Bot', value: `${message.author.bot}`, inline: true },
          { name: 'Is Owner', value: `${message.author.id === owner}`, inline: true },
        )
        .setTimestamp()
        .setFooter('');
      message.channel.send({ embeds: [embed]});
    }
  }
}); ` ` `

您可以使用 message.mentions.members.first() 而不是 message.mentions.users.size。要使此命令有效,您还可以使用 if() {} else if() {} 语句。例如:

if(!args[0]) {
   //This is the part for non-mentioned members. 
} else if(args[0]) {
   //This is the part for mentioned members.
}

你也可以使用if() {} else {}语句。

if(!args[0]) {
   //This is the part for non-mentioned members.
} else {
   //This is the part for mentioned members.
}

另外:

 if(!args[0]) {
   const author = message.author.id //or you can do message.author also
   //Then your codes here
} else {
   const member = message.mentions.members.first() //You can use ID's also
   //Then your codes here. 
}

embed 上使用它。这不是关于成员的正确调用

{ name: 'ID', value: `${message.mentions.users.first().id}`, inline: true }, 

所以改成:

{ name: 'ID', value: `${member.user.id}`, inline: true },