且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Discord.js 多角色检查

更新时间:2023-11-30 12:38:22

如果要使用数组,可以使用 foreach 和 bool 检查用户是否有 any数组中的角色,您也应该在 discord.js v12 中使用 .cache.some 而不是 find,如 这里

If you want to use an array, you can use a foreach and a bool check to check if the user has any of the roles in the array, also you should use .cache.some instead of find in discord.js v12 as seen here

例子:

var morsmordreRoles = [
        'Dev',
        'Renowned Wizard',
        'Pheonix',
        'Moderator'
    ]
    var hasRole = false;
    morsmordreRoles.forEach(findrole =>{
        if(message.member.roles.cache.some(role => role.name === findrole)) hasRole = true; //if user has role, sets bool to true
    })

    if(hasRole === true){
        //code when has role
    }
    else{
        //code when has no role
    }