我需要创建一个命令,首先从所有以星号开头的角色中删除该成员,然后分配一个将在命令参数中传递的角色。exports.run = (client, message, [where]) => { var role = message.guild.roles.cache.find(role => role.name === where); if (role && where.substring(0, 1) == '*') { //remove all roles that start with * from the member, probably some kind of for loop? message.member.roles.add(role); message.channel.send(message.member.nickname + ' entered the channel ' + where + '.'); } else message.channel.send('Channel' + where + ' does not exist or does not start with *.');};你能帮我解决那个for循环吗?谢谢。
1 回答
慕莱坞森
TA贡献1810条经验 获得超4个赞
您的解决方案是:
const roles = message.member.roles.cache.array();
for (var i = 0; i < roles.length; i++) {
if (roles[i].name.substring(0, 1) == "*") {
message.member.roles.remove(roles[i]);
}
}
添加回答
举报
0/150
提交
取消