本文介紹了如何顯示用戶 discord.js/userinfo 命令的角色的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!
問題描述
我正在嘗試創建一個 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模板網!
【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!