无法读取属性' name' discord.js中的null

时间:2017-09-15 01:50:22

标签: javascript discord discord.js

if (command === "info") {
    let user = message.mentions.users.first();
    const status2 = message.author.presence.status;
    const games2 = message.author.presence.game.name;
    const untaggedembed = new Discord.RichEmbed()
        .setThumbnail(message.author.avatarURL)
        .setColor(0xE69A49)
        .addField("Account Username:", `${message.author.username}#${message.author.tag}`)
        .addField("User ID:", message.author.id)
        .addField("Discord user was created on:", message.author.createdAt.toDateString())
        .addField("Discord user joined on:", message.guild.joinedAt.toDateString())
        .addField("Playing: ", games2 !== null ? games2 : "None", true)
        .addField("Last Message: ", message.author.lastMessage !== null ? message.author.lastMessage : "None", true)
        .addField("User Status: ", status2)
    if (message.mentions.users.size < 1) return message.channel.sendEmbed(untaggedembed)
    if (!user === '@Robot Hamster') return message.channel.send("Can't get info for Robot Hamster ")
    const status = user.presence.status;
    const games = user.presence.game.name;
    // If a user is tagged
    const taggedembed = new Discord.RichEmbed()
        .setThumbnail(user.avatarURL)
        .setColor(0xE69A49)
        .setDescription("This is " + user.username + "'s" + " Discord Info!")
        .addField("Account Username:", `${user.username}#${user.discriminator}`)
        .addField("User ID:", user.id)
        .addField("Is this User a Bot [T/F]: ", user.bot)
        .addField("Discord user was created on:", user.createdAt.toDateString())
        .addField("Discord user joined on:", message.guild.joinedAt.toDateString())
    addField("Playing: ", games !== null ? games : "None", true)
    .addField("Last Message: ", user.lastMessage !== null ? user.lastMessage : "None", true)
    .addField("User Status: ", status)
    .setFooter("Requested by: " + message.author.username) message.channel.sendEmbed(taggedembed);
}

即时通讯无法阅读财产&#39; name&#39;在addField中为null(&#34;播放:&#34;,游戏!== null?游戏:&#34;无&#34;,true)不确定是什么问题,但任何帮助都会被赞赏为im丢失

1 个答案:

答案 0 :(得分:-1)

if (command === "info") {
let user = message.mentions.users.first();
const status2 = message.author.presence.status;
const games2 = message.author.presence.game.name;
const untaggedembed = new Discord.RichEmbed()
    .setThumbnail(message.author.avatarURL)
    .setColor(0xE69A49)
    .addField("Account Username:", `${message.author.username}#${message.author.tag}`)
    .addField("User ID:", message.author.id)
    .addField("Discord user was created on:", message.author.createdAt.toDateString())
    .addField("Discord user joined on:", message.guild.joinedAt.toDateString())
    .addField("Playing: ", games2 !== null ? games2 : "None", true)
    .addField("Last Message: ", message.author.lastMessage !== null ? message.author.lastMessage : "None", true)
    .addField("User Status: ", status2)
if (message.mentions.users.size < 1) return message.channel.sendEmbed(untaggedembed)
if (!user === '@Robot Hamster') return message.channel.send("Can't get info for Robot Hamster ")
const status = user.presence.status;
const games = user.presence.game.name;
// If a user is tagged
const taggedembed = new Discord.RichEmbed()
    .setThumbnail(user.avatarURL)
    .setColor(0xE69A49)
    .setDescription("This is " + user.username + "'s" + " Discord Info!")
    .addField("Account Username:", `${user.username}#${user.discriminator}`)
    .addField("User ID:", user.id)
    .addField("Is this User a Bot [T/F]: ", user.bot)
    .addField("Discord user was created on:", user.createdAt.toDateString())
    .addField("Discord user joined on:", message.guild.joinedAt.toDateString())
.addField("Playing: ", games !== null ? games : "None", true)
.addField("Last Message: ", user.lastMessage !== null ? user.lastMessage : "None", true)
.addField("User Status: ", status)
.setFooter("Requested by: " + message.author.username) message.channel.sendEmbed(taggedembed);

这有用吗?我想它应该有效。