add user to role with newest discord.js

时光总嘲笑我的痴心妄想 提交于 2020-05-09 07:42:39

问题


i'm using newest discord.js in node.js and i'm trying to add user to role, but it seems bot.addUserToRole() was removed.

How can I do it when I know only rank name, not it's ID?


回答1:


You can do this with:

var role = message.guild.roles.find(role => role.name === "MyRole");
message.member.addRole(role);



回答2:


Here's what worked for me, hope this helps!

var role= member.guild.roles.cache.find(role => role.name === "role name");
member.roles.add(role);

Here is the official documentation on it.



来源:https://stackoverflow.com/questions/49599732/add-user-to-role-with-newest-discord-js

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!