if (command === 'whois') {
let user;
if (message.mentions.users.first()) {
user = message.mentions.users.first();
} else {
user = message.author;
}
const member = message.guild.member(user);
const embed = new Discord.MessageEmbed()
.setColor("RANDOM")
.setThumbnail(`${member.user.displayAvatarURL({ dynamic: true })}`)
.addField(`${user.tag}`, `${user}`, true)
.addField("ID:", `${user.id}`, true)
.addField("Nickname:", `${member.nickname !== null ? `${member.nickname}` : 'None'}`, true)
.addField("Status:", user.presence.status, true)
.addField("Playing", `${member.user.presence.activities} `)
.addField("Joined Discord At", member.user.createdAt)
.addField("Roles", member.roles.cache.map(r => '`'+r.name+'`').join(' - '), true)
.setFooter(`${client.user.username}`)
message.channel.send(embed);
}
我不断收到错误消息 (node:19788) UnhandledPromiseRejectionWarning: DiscordAPIError: Invalid Form Body 我不知道该怎么办。
答案 0 :(得分:1)
您只需更改此行:
.addField("Playing", `${member.user.presence.activities}`)
进入
.addField("Playing", `${member.user.presence.activities[0]}`)
因为活动存储在一个数组中,但您只需要第一个值。如果用户什么都不做,则为 undefined
。所以你可以这样做:
.addField("Playing", `${member.user.presence.activities[0] !== undefined ? member.user.presence.activities[0].name} : "Nothing."`)
P.S:如果您想查看活动,只需console.log(member.user.presence.activities[0])
。