add user to role with newest discord.js

后端 未结 4 1989
执笔经年
执笔经年 2020-12-12 03:13

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

4条回答
  •  攒了一身酷
    2020-12-12 03:38

    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);
    

提交回复
热议问题