简体   繁体   中英

How do I get my discord bot to check if a member has a role?

I'm making a discord bot and there's a command where I want only admins to be able to use, but when I try to check if the user has a role, it says that it can't read the property 'roles' of undefined. Here's the code I'm using

if(command === '!cmd') {
        if(message.author.id != ownerid || !message.member.roles.has(370565560972476437)) {
            messagesend("YOU ARE NOT ALLOWED TO USE THIS COMMAND\nTHIS IS YOUR ONLY WARNING")
            console.log(message.author);
        } else if(message.author.id === ownerid || message.member.roles.has("370565560972476437") || message.member.roles.some(r=>["admin"].includes(r.name))) {
            var messageArrray = messageArray.slice(1,messageArray.length)
            let evalStr = ""
            for(let element of messageArrray){
                evalStr += element + " "
            }
            console.log(evalStr);
            eval(evalStr)
            message.delete()
        }
    }

 if (message.guild.members.get(message.author.id).roles.exists('name','ROLENAME'){ ///Code here } 

Thats all.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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