admin管理员组

文章数量:1180493

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?

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?

Share Improve this question edited Apr 1, 2018 at 20:12 ecg8 1,3921 gold badge13 silver badges16 bronze badges asked Apr 1, 2018 at 15:40 GuyWhoDoThingsGuyWhoDoThings 851 gold badge1 silver badge5 bronze badges 1
  • I recommend asking on their official Discord server. discordapp.com/invite/bRCvFy9 – Joseph Webber Commented Apr 1, 2018 at 16:05
Add a comment  | 

4 Answers 4

Reset to default 18

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.

You can do this with:

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

For me (right now) this works only:

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

As of now, 2020, this Code works fine, and its easy to implement since its only based on the message object

let role = message.member.guild.roles.cache.find(role => role.name === "your role");
if (role) message.guild.members.cache.get(message.author.id).roles.add(role);

本文标签: javascriptadd user to role with newest discordjsStack Overflow