简体   繁体   English

使用 discord.js 获取有关提到的用户/消息作者的信息

[英]Get information about the mentioned user / message author with discord.js

**• Server Roles:** <@&${user._roles.join('> <@&')}> , ^^ Cannot read property 'join' of undefined I used message.member._roles.join('> <@&')}>`, But it always showed the roles of the user that wrote the command, and not the user that you mentioned. **• Server Roles:** <@&${user._roles.join('> <@&')}> , ^^ 无法读取未定义的属性 'join' 我使用了 message.member._roles.join(' > <@&')}>`,但它总是显示编写命令的用户的角色,而不是你提到的用户。

Message.member is user who sent this message. Message.member 是发送此消息的用户。 If you want to get mentioned guild members you need to use message.mentions.members which returns an collection of mentioned users.如果您想获得提及的公会成员,您需要使用message.mentions.members返回提及用户的集合。
Your code should look like:您的代码应如下所示:

// To make sure that only one member is mentioned
if(message.mentions.members.size == 1){
    const roles = `<@&${message.mentions.members.first()._roles.join('> <@&')}>`
    message.channel.send(roles);
}

I recommend sending empty message first and then editing its content to add these mentions just to avoid pinging whole server.我建议先发送空消息,然后编辑其内容以添加这些提及,以避免 ping 整个服务器。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM