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

2022-01-10 00:00:00 node.js javascript discord.js

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

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

解决方案

这对我有用,希望对你有帮助!

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

这里是它的官方文档.p>

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?

解决方案

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.

相关文章