Random Guy
Random Guy

Reputation: 79

discord.js v12 User Info Command

I made a userinfo command for my discord bot. It was working fine until it stopped working as expected. Everything works fine except the user's status part. In the code below the bot is supposed to send the user's status [ online, idle, dnd or offline ] however It seems to always send Offline while secondly if a user is playing/listening/streaming anything it is supposed to show that as well. However it doesn't show any of that. Can you help me out? Thanks in advance! Here is my code:

module.exports = {
 name: "userinfo",
 description: "Userinfo of mentioned user/id or if no one mentioned then yours",
run: async(client,message,args,guild) => {
      const embed = new MessageEmbed()
const moment = require('moment');

const member =  message.mentions.members.first() || message.guild.members.cache.get(args[0]) || message.member;
if (!member) 
     return message.channel.send('Please mention the user for the userinfo..');
   const userFlags = (await member.user.fetchFlags()).toArray();
   const activities = [];
   let customStatus;
   for (const activity of member.presence.activities.values()) {
     switch (activity.type) {
       case 'PLAYING':
         activities.push(`Playing **${activity.name}**`);
         break;
       case 'LISTENING':
         if (member.user.bot) activities.push(`Listening to **${activity.name}**`);
         else activities.push(`Listening to **${activity.details}** by **${activity.state}**`);
         break;
       case 'WATCHING':
         activities.push(`Watching **${activity.name}**`);
         break;
       case 'STREAMING':
         activities.push(`Streaming **${activity.name}**`);
         break;
       case 'CUSTOM_STATUS':
         customStatus = activity.state;
         break;
     }
   }
   const uiembed = new MessageEmbed() 
     .setTitle(`${member.displayName}'s Information`)
     .setThumbnail(member.user.displayAvatarURL({ dynamic: true }))
     .addField('User', member, true)
     .addField('Discriminator', `\`#${member.user.discriminator}\``, true)
     .addField('ID', `\`${member.id}\``, true)
     .addField('Status', statuses[member.presence.status], true)
     .addField('Bot', `\`${member.user.bot}\``, true)
     .addField('Color Role', member.roles.color || '`None`', true)
     .addField('Highest Role', member.roles.highest, true)
     .addField('Joined server on', `\`${moment(member.joinedAt).format('MMM DD YYYY')}\``, true)
     .addField('Joined Discord on', `\`${moment(member.user.createdAt).format('MMM DD YYYY')}\``, true)
     .setFooter(message.member.displayName,  message.author.displayAvatarURL({ dynamic: true }))
     .setTimestamp()
     .setColor(member.displayHexColor);
  if (activities.length > 0) uiembed.setDescription(activities.join('\n'));
   if (customStatus) uiembed.spliceFields(0, 0, { name: 'Custom Status', value: customStatus});
   if (userFlags.length > 0) uiembed.addField('Badges', userFlags.map(flag => flags[flag]).join('\n'));
   message.channel.send(uiembed);
   }
 }



Upvotes: 3

Views: 8691

Answers (1)

Legendary Emoji
Legendary Emoji

Reputation: 228

You have to turn on intents from discord developer portal

  1. Go To Discord Developer Portal > Applications > Your Application (Bot)
  2. In Your Application (Bot) Go To Settings > Bot Section
  3. Scroll Down To Privileged Gateway Intents
  4. Turn On PRESENCE INTENT (You Have To Do Verification If Your Bot Is In 100+ Guilds)

Thats It, Now Please Restart Bot & Try Again

Upvotes: 3

Related Questions