discord.js v12 用户信息命令
Posted
技术标签:
【中文标题】discord.js v12 用户信息命令【英文标题】:discord.js v12 User Info Command 【发布时间】:2021-05-04 01:05:40 【问题描述】:我为我的 discord 机器人创建了一个 userinfo 命令。它工作正常,直到它按预期停止工作。除了用户的状态部分外,一切正常。在下面的代码中,机器人应该发送用户的状态 [在线、空闲、dnd 或离线] 但是它似乎总是发送离线,其次如果用户正在播放/收听/流式传输任何它应该显示的内容。但是,它没有显示任何内容。你能帮我吗?提前致谢! 这是我的代码:
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);
【问题讨论】:
【参考方案1】:你必须从discord developer portal开启意图
-
转到 Discord 开发者门户 > 应用程序 > 您的应用程序 (Bot)
在您的应用程序 (Bot) 中转到设置 > Bot 部分
向下滚动到特权网关意图
开启 PRESENCE INTENT(如果您的机器人在 100 多个公会中,您必须进行验证)
就是这样,现在请重新启动机器人并重试
【讨论】:
以上是关于discord.js v12 用户信息命令的主要内容,如果未能解决你的问题,请参考以下文章