我有一个!!userinfo命令,我正在尝试将其到达@anyone所在的位置,它在此显示信息,说明我如何进行其他所有操作,但后来我想到了这个问题,这里是错误。


  UnhandledPromiseRejectionWarning:TypeError:无法读取未定义的属性“ map”


我没有找到任何答案,但是我确实想出了一个说它通常表示没有人居住的地方,但是我不知道如何将其放入那里。

const Discord = module.require("discord.js");
const fs = require("fs");
const userdata = JSON.parse(fs.readFileSync('commands/storage/userdata.json', 'utf8'));

module.exports.run = async (bot, message, args) => {
    let member;
    if (message.mentions.users > 0) {
        member = message.mentions.user.size()
    } else {
        member = message.author
    }
    let user;
    if (message.mentions.users > 0) {
        user = message.mentions.user.size()
    } else {
        user = message.author
    }

    embed = new Discord.RichEmbed()
        .setAuthor(message.member.username)
        .setDescription("Users Info", true)
        .setColor("#64FF00", true)
        .addField("Full Username:", `${message.member.username}${message.member.discriminator}`, true)
        .addField("ID:", message.member.id, true)
        .addField("Created at:", message.member.createdAt, true)
        .addField("Status:", `${user.presence.status}`, true)
        .addField("Game:", `${user.presence.game}`, true)
        .addField("Roles", member.roles.map(r => `${r}`).join('|'), true);

    message.channel.send(embed);
}

module.exports.help = {
    name: "userinfo"
}


我想要它,所以我可以@anyone,出现信息

最佳答案

我相信问题在于如何为变量member分配值。除此之外,我认为您有一些冗余代码,因为您有一个变量member和一个变量user,它们使用相同的代码提供了一个值。

在下面,您可以找到我已重写的代码。试试看,让我知道结果如何。

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

  if (message.mentions.members.first()) {
    guildMember = message.mentions.members.first();
  } else {
    guildMember = message.member;
  }

  // We need the User object aswell for different properties
  const user = guildMember.user;

  let embed = new Discord.RichEmbed()
    .setAuthor(user.username)
    .setDescription("Users Info", true)
    .setColor("#64FF00", true)
    .addField("Full Username:", `${user.username}${user.discriminator}`, true)
    .addField("ID:", user.id, true)
    .addField("Created at:", user.createdAt, true)
    .addField("Status:", `${user.presence.status}`, true)
    .addField("Game:", `${user.presence.game}`, true)
    .addField("Roles", guildMember.roles.map(r => `${r}`).join('|'), true);

  message.channel.send(embed);
}

10-06 04:04