简体   繁体   English

在具有 discord.js 的 Discord 服务器上为每个用户分配一个角色

[英]Assign every user a role on a Discord Server with discord.js

I'd like to add a role to every user on a Discord Server.我想为 Discord 服务器上的每个用户添加一个角色。 I am using "discord.js".我正在使用“discord.js”。 I know how to assign a role to a specific user, but I do not know how to do the same thing to every user.我知道如何为特定用户分配角色,但我不知道如何对每个用户做同样的事情。

Here is my current code:这是我当前的代码:

//defines the role to a variable
var role = message.guild.roles.cache.find(role => role.name === "myRole");

Thanks for your help:)谢谢你的帮助:)

You'll have to loop through each member of the guild and add the respective role.您必须遍历公会的每个成员并添加各自的角色。

var role = message.guild.roles.cache.find(role => role.name === "myRole"); // Getting the role
message.guild.members.cache.forEach(member => { // Looping through each member.
    member.roles.add(role); // Adding the role.
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM