Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
76 views
in Technique[技术] by (71.8m points)

javascript - How to check member permissions via function [discord.js]

Currently I'm making a Discord Bot using discord.js and node.js. I have made a lot of moderation commands and because of that I need to constantly check if some members have some permisisons, I ran into the necessity of making a function to check member permissions. This is mainly because of when you try to mderate a member that is either a Mod or an Admin, which makes my code more complicated than it actually is (I'm fairly new on coding bots by the way).

I'm trying to check the permissions of an specified member by using a function. What I expect to happen is that when you call the function, it will check if the member has such permissions and return a boolean.

What I have tried so far is this:

function isMod(str) {
    str.permissions.has(ANY_PERMISSION_TAG);
} // This should check for the permissions of any member specified by replacing 'str'

return console.log(isMod(message.member)); // This should return a boolean | true: Has at least 1 of the permissions | false: Does not have any of the permissions

However, the code above does not work, even by what I believe is the equivalent of this code below:

console.log(message.member.permissions.has(ANY_PERMISSION_TAG));

I don't know how to make isMod work, please help!

question from:https://stackoverflow.com/questions/65928040/how-to-check-member-permissions-via-function-discord-js

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

you forgot the return in the function

function isMod(str) {
   return str.permissions.has(ANY_PERMISSION_TAG);
} // This should check for the permissions of any member specified by replacing 'str'
    
return console.log(isMod(message.member)); // This should return a boolean | true: Has at least 1 of the permissions | false: Does not have any of the permissions

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...