Friday, February 23, 2024
 Popular · Latest · Hot · Upcoming
123
rated 0 times [  127] [ 4]  / answers: 1 / hits: 5129  / 3 Years ago, wed, july 28, 2021, 12:00:00

Problem: I have been trying to add a "Activity" field to my info command, and its not working.


Expected result: Responds with the other stuff, along with the Activity field, showing what the user is doing.


Actual response: Shows everything else correctly, except the Activity field, which says undefined/null.


Code:


if (command == "info") {
const embed = new Discord.MessageEmbed()
let member = message.mentions.members.first() || message.guild.members.cache.get(args[1]) || message.guild.member(message.author)
const Roles = new Array()
message.guild.roles.cache.forEach(role => {
if (member.roles.cache.find(r => r.id == role.id)) {
Roles.push(role)
}
})
console.log(member.presence)
embed.setAuthor(user.tag, member.user.avatarURL())
embed.setTitle(`👋 Welcome to ${user.username}'s Profile!`)
embed.addField('#️⃣ Tag:', member.user.tag)
embed.addField('📡 Joined Guild at:', member.user.joinedAt)
embed.addField('💬 Joined Discord at:', member.user.cretedAt
)
if (!member.presence.activities) {
embed.addField('⚽️ Activity:', 'Not playing anything')
} else {
embed.addField('⚽️ Activity:', `${member.presence.activities.type} ${member.presence.activities.name}n${member.presence.activities.details}n${member.presence.activities.state}`)
}
embed.addField('📱 Platform:', member.presence.clientStatus)
embed.addField('🤖 Bot:', user.bot)
embed.addField('📜 Roles:', Roles.join(' | '))
embed.setFooter('Bot made with discord.js')
message.channel.send(embed)
}

More From » node.js

 Answers
10

Presence.activities is an array of Activity.


// Add check for empty activities array
if (!member.presence.activities || member.presence.activities.length == 0) {
embed.addField('⚽️ Activity:', 'Not playing anything')
} else {
const activity = member.presence.activities[0];
embed.addField('⚽️ Activity:', `${activity.type} ${activity.name}n${activity.details}n${activity.state}`);
}

Most of the time you will only need the first item of the array. Because you rarely see users with multiple activities.


[#1050] Tuesday, July 20, 2021, 3 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
jamila

Total Points: 490
Total Questions: 94
Total Answers: 94

Location: Lebanon
Member since Sun, Aug 2, 2020
4 Years ago
;