Discord.js - 删除所有以 *(星号)开头的角色

我需要创建一个命令,首先从所有以星号开头的角色中删除该成员,然后分配一个将在命令参数中传递的角色。


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循环吗?谢谢。


茅侃侃
浏览 96回答 1
1回答

慕莱坞森

您的解决方案是:const roles = message.member.roles.cache.array();for (var i = 0; i < roles.length; i++) {&nbsp; &nbsp; &nbsp; if (roles[i].name.substring(0, 1) == "*") {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; message.member.roles.remove(roles[i]);&nbsp; &nbsp; &nbsp; }}
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

JavaScript