如何在Discord.js v12中使用user.bot?

时间:2020-09-01 13:44:47

标签: javascript node.js discord discord.js

我正在执行用户信息命令,并且希望它告诉用户该用户是否是机器人。它会对&profile {user ping / user ID}做出反应,没有给出参数会使该机器人显示有关您的信息。到目前为止,我的代码如下:

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 isBot = 0;
  if (userinfoget.bot) {
   isBot = 'This account is a bot';
  } else {
   isBot = "This account isn't a bot";
  }

  var status = userinfoget.presence.status;
  if (status == 'online') {
   status = `<:statusonline:750346592242106368> This user is currently online`;
  } else if (status == 'idle') {
   status = `<:statusidle:750346522847215760> This user is currently idle`;
  } else if (status == 'dnd') {
   status = `<:statusdnd:750346486398582815> This user has currently do not disturb mode on`;
  } else if (status == 'offline') {
   status = `<:statusoffline:750346558809047090> This user is currently offline (or lurking <:lurklias:750342622463262751>)`;
  } else {
   status == `Unable to get user's status`;
  }

  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}`);
  var joinDate = new Date(userinfoget.joinedAt);
  var today = Date.now();
  var timeFromJoining = today - joinDate;
  var timeFromJoiningDate = new Date(timeFromJoining).toLocaleDateString();
  console.log(timeFromJoining);
  console.log(timeFromJoiningDate);

  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'),
    } // 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);
 },
};

,但是即使显示的是自身信息(机器人),它也始终显示This account isn't a bot。我没有任何错误。我做错了什么?谢谢。

1 个答案:

答案 0 :(得分:1)

bot不是GuildMember的属性;它是User

的属性
userinfoget.user.bot