简体   繁体   中英

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:


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

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 . 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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