I'm making a user info command in my discord bot using discord.js v12. The only problem I have with it is, that if an user doesn't have any roles, the highest role shows as @@everyone, not @everyone. So I would like to avoid it, and make it so if the user doesn't have any roles, it will say 'This user has no roles in this server'. My code is here (only the bit that has anything to do with the roles):
const { DiscordAPIError } = require("discord.js");
const Discord = require("discord.js");
const moment = require("moment");
module.exports = {
name: "profile",
description: "The bot will return the info about the user",
execute(message, args){
let userinfoget = message.mentions.members.first() || message.guild.members.cache.get(args[0]) || message.member
var highestRoleID = userinfoget.roles.highest.id;
var joined = moment(userinfoget.joinedAt).format('DD/MM/YY, HH:mm:ss')
console.log(`Highest role = ${highestRoleID}`);
console.log(`User = ${userinfoget}`);
console.log(userinfoget.roles)
if(!userinfoget.roles) console.log('no roles')
const embed = new Discord.MessageEmbed()
.setColor(userinfoget.displayHexColor)
.setAuthor(`${userinfoget.user.tag}`, userinfoget.user.displayAvatarURL())
.addFields(
{name: `User ping`,
value: `<@${userinfoget.id}>`}
)
.addFields(
{name: `User ID`,
value: `${userinfoget.id}`}
)
.addFields(
{name: 'Joined Server',
value: moment(userinfoget.joinedAt).format('LLLL') + ' ' + timeFromJoiningServerMessage} // or moment(userinfoget.joinedAt).format('DD/MM/YY, HH:mm:ss')
)
.addFields(
{name: 'Joined Discord',
value: moment(userinfoget.user.createdAt).format('LLLL')} // or moment(userinfoget.createdAt).format('DD/MM/YY, HH:mm:ss')
)
.addFields(
{name: 'Highest role',
value: `<@&${highestRoleID}>`}
)
.addFields(
{name: 'Online Status',
value: `${status}`}
)
.addFields(
{name: 'Is a bot?',
value: `${isBot}`}
)
.setFooter('Bot made by mkpanda')
message.channel.send(embed);
}
As you can see, I tried doing !userinfoget.roles
, but when logging it, it shows all the information about the user, not just the roles. How could I detect whether an user has any role or not? Thanks in advance :)
addFields()
is that you can add multiple fields at once. I suggest you condense your embed structure. – Lioness100