javascript 使用最新的 discord.js 将用户添加到角色

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/49599732/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-29 08:38:48  来源:igfitidea点击:

add user to role with newest discord.js

javascriptnode.jsdiscord.js

提问by GuyWhoDoThings

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.

我在 node.js 中使用最新的 discord.js 并且我正在尝试将用户添加到角色,但似乎 bot.addUserToRole() 已被删除。

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

当我只知道等级名称而不知道 ID 时,我该怎么做?

回答by André

You can do this with:

你可以这样做:

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

回答by Y. Georgiev

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

Hereis the official documentation on it.

是关于它的官方文档。