javascript - discord.js v12 User Info Command - Stack Overflow

I made a userinfo mand for my discord bot. It was working fine until it stopped working as expected. Ev

I made a userinfo mand 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);
   }
 }



I made a userinfo mand 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);
   }
 }



Share Improve this question asked Jan 30, 2021 at 8:02 Random GuyRandom Guy 792 silver badges7 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 3

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

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745383302a4625329.html

相关推荐

  • javascript - discord.js v12 User Info Command - Stack Overflow

    I made a userinfo mand for my discord bot. It was working fine until it stopped working as expected. Ev

    8小时前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信