简体   繁体   English

discord.js 中的用户信息命令

[英]User info command in discord.js

Hi so I'm learning by myself to code a discord bot in JavaScript but I have this error and I don't understand if I missed something TypeError: Cannot read property 'users' of undefined And here is what I did:嗨,我正在自学在 JavaScript 中编写 discord 机器人,但我有这个错误,我不明白我是否错过了一些东西TypeError: Cannot read property 'users' of undefined这就是我所做的:


module.exports.run = async (bot, message, args) => {

  const user = message.mentions.users.first() || message.author;
  const member = message.mentions.members.first() || message.member;
  
  let embed = new Discord.RichEmbed()
  .setAuthor(user.tag)
  .setDescription("Users Info", true)
  .setColor("#64FF00", true)
  .addField("Full Username:", user.tag , true)
  .addField("ID:", user.id, true)
  .addField("Created at:", user.createdAt, true)
  .addField("Status:", user.presence.status , true)
  .addField("Game:", user.presence.game ? user.presence.game : 'none' , true)
  .addField("Roles", member.roles.map(r => `${r}`).join(' | '), true);
message.channel.send(embed);
}

EDIT : I figured out my code was outdated xD编辑:我发现我的代码已经过时了 xD

The error itself provides the answer.错误本身提供了答案。 It says TypeError: Cannot read property 'users' of undefined that means there is a property of which you want to read users from in your case its message.mentions.users .它说TypeError: Cannot read property 'users' of undefined这意味着有一个属性你想从你的情况下读取用户的message.mentions.users In this it says that mentions is undefined.在这它说提及是未定义的。 This could mean that there was some other error or that it was never mentioned.这可能意味着存在其他错误或从未提及。 You can use message.mentions?.users if in angular it says if mentions is undefined then return undefined do not check its users value.您可以使用message.mentions?.users如果在 angular 中它说如果提及未定义则返回未定义不检查其用户值。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM