我正在尝试创建一个 userinfo 命令,但目前我一直在显示用户的角色.
I'm trying to make a userinfo command, and I'm currently stuck on showing roles of the user.
这是我的代码:
const Discord = module.require('discord.js');
const moment = require('moment');
module.exports.run = async (bot, message, args) => {
let user = message.mentions.users.first() || message.author;
const joinDiscord = moment(user.createdAt).format('llll');
const joinServer = moment(user.joinedAt).format('llll');
let embed = new Discord.RichEmbed()
.setAuthor(user.username + '#' + user.discriminator, user.displayAvatarURL)
.setDescription(`${user}`)
.setColor(`RANDOM`)
.setThumbnail(`${user.displayAvatarURL}`)
.addField('Joined at:', `${moment.utc(user.joinedAt).format('dddd, MMMM Do YYYY, HH:mm:ss')}`, true)
.addField('Status:', user.presence.status, true)
.addField('Roles:', user.roles.map(r => `${r}`).join(' | '), true)
.setFooter(`ID: ${user.id}`)
.setTimestamp();
message.channel.send({ embed: embed });
return;
}
module.exports.help = {
name: 'userinfo'
}
我收到此错误TypeError: Cannot read property 'map' of undefined,我不知道如何解决?
I'm getting this error TypeError: Cannot read property 'map' of undefined and I don't know how to fix it?
User.roles 是 undefined 因为该属性不存在:尝试使用 GuildMember.roles:
User.roles is undefined because that property doesn't exist: try using GuildMember.roles instead:
let member = message.mentions.members.first() || message.member,
user = member.user;
let embed = new Discord.RichEmbed()
// ... all the other stuff ...
.addField('Roles:', member.roles.map(r => `${r}`).join(' | '), true)
其他属性仍会使用user,但.roles会与GuildMember相关.
The other properties will still use user, but .roles will be related to the GuildMember.
这篇关于如何显示用户 discord.js/userinfo 命令的角色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!
使用 discord.js 检测图像并响应Using discord.js to detect image and respond(使用 discord.js 检测图像并响应)
检查 Discord 服务器中是否存在用户 IDCheck if user ID exists in Discord server(检查 Discord 服务器中是否存在用户 ID)
公会成员添加不起作用(discordjs)Guild Member Add does not work (discordjs)(公会成员添加不起作用(discordjs))
使用 REPLIT 创建我的第一个机器人,但总是错误Creating my first bot using REPLIT but always error Discord.JS(使用 REPLIT 创建我的第一个机器人,但总是错误 Discord.JS)
如何为我的 Discord.js 机器人编写事件/命令处理程How do I code event/command handlers for my Discord.js bot?(如何为我的 Discord.js 机器人编写事件/命令处理程序?)
如何从 Discord.js 中的用户名中查找用户 ID?How to find a User ID from a Username in Discord.js?(如何从 Discord.js 中的用户名中查找用户 ID?)