我想在管理员输入激活(用户)时向用户添加角色,机器人为用户提供 3 个角色,这是我的代码
if (message.content === 'activate') {
const guild = message.guild;
const role = message.guild.roles.cache.get('842121303616126977');
const member = message.mentions.members.first
member.roles.add(role);
}
});
答案 0 :(得分:2)
GuildMemberRoleManager.add
接受一个 RoleResolvable
数组,它可以是 Role
的一个实例,也可以是一个 Snowflake
。
if (message.content === "activate") {
const member = message.mentions.members.first(); // Note that first is a method, not a property.
if (!member) return message.channel.send("Member not found.");
member.roles.add(["RoleID1", "RoleID2", "RoleID3"]);
}
答案 1 :(得分:0)
这行得通
this code worked for me finally `client.on('message', message => {
if (!message.content.startsWith(prefix) || message.author.bot) return;
const args = message.content.slice(prefix.length).split(/ +/);
console.log(args);
const command = args.shift().toLowerCase();
if (command == 'activate') {
const member = message.mentions.members.first(); // Note that first is a method, not a property.
if (!member) return message.channel.send("member not found");
const drole = message.guild.roles.cache.get('842121300532920362');
const prole = message.guild.roles.cache.get('842121301777973298');
const lrole = message.guild.roles.cache.get('842121302708977694');
const frole = message.guild.roles.cache.get('842121305854836826');
member.roles.add(drole);
member.roles.add(lrole);
member.roles.add(prole);
member.roles.remove(frole);
message.channel.send('activated' + ' <' + '@' + member + '>');
}
});`