I am trying to make a userinfo command, however, under the Roles bit, it errors saying:
TypeError: target.roles.map is not a function
Expected result:
console.log(target.roles.map(r => `${r}`).join(" ,"))
It will log out the roles that they have in the specific server.
Actual result:
console.log(target.roles.map(r => `${r}`).join(" ,")
It will log: TypeError: target.roles.map is not a function
What have I tried?
I tried doing:
console.log(target.roles.cache.map(r => `${r}`).join(" ,"))
Still logged the same thing but it has cache before the .map
.
Code:
const {Client, CommandInteraction, MessageEmbed} = require('discord.js')
const moment = require('moment')
module.exports = {
name: 'userinfo',
description: "show the info type",
type: 'CHAT_INPUT',
options: [
{
name: 'target',
description: 'target to get info on',
type: 'USER',
required: false
}
],
default_permission: true,
/**
*
* @param {Client} client
* @param {CommandInteraction} int
* @param {String[]} args
*/
run: async(client, int, args) => {
const target = int.options.getMember('target') || int.member
let status;
let statusEmoji
switch (target.presence.status) {
case "online":
status = 'Online'
statusEmoji = client.emojis.cache.get(`960628219608985650`)
break;
case "idle":
status = 'Idle'
statusEmoji = client.emojis.cache.get(`960628219621572638`)
break;
case "dnd":
status = 'Do not Disturb'
statusEmoji = client.emojis.cache.get(`960628123806879744`)
break;
case "offline":
status = 'Offline'
statusEmoji = client.emojis.cache.get(`960628219550249071`)
break;
}
const embed = new MessageEmbed()
.setColor('YELLOW')
.setTitle(`${target.user.tag}'s Info`)
.setThumbnail(target.user.displayAvatarURL({ dynamic: true }))
.addFields(
{
name: ':bust_in_silhouette: | Username:',
value: `${target.user.username}`,
inline: false
},
{
name: ':busts_in_silhouette: | Nickname (Guild Username):',
value: target.nickname ? `${target.nickname}` : `Same as discord username!`,
inline: false
},
{
name: ':hash: | Discriminator:',
value: `${target.user.discriminator}`,
inline: false
},
{
name: ':id: | User ID:',
value: `${target.user.id}`,
inline: false
},
{
name: `${client.emojis.cache.get('960628123806879744')} | Current Status:`,
value: `${statusEmoji} | ${status}`,
inline: false
},
{
name: `:video_game: | Activity:`,
value: target.presence.activities ? target.presence.activities[1].name : "This user isn't on activity!",
inline: false
},
{
name: `:new: | Registered at:`,
value: moment.utc(target.user.createdAt).format('dddd, MMMM Do YYYY, HH:mm:ss'),
inline: false
},
{
name: `:speech_balloon: | Joined at:`,
value: moment.utc(target.joinedAt).format('dddd, MMMM Do YYYY, HH:mm:ss'),
inline: false
},
{
name: `Roles:`,
value: target.roles.map(r => `${r}`).join(" ,"),
inline: false
}
)
.setTimestamp()
int.followUp({ embeds: [ embed ] })
}
}