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
4 Answers
Reset to default 18Here'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
版权声明:本文标题:javascript - add user to role with newest discord.js - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1738145891a2065925.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论