简体   繁体   中英

`TypeError: member.hasPermission() is not a function` when checking permissions in discord.js

I am trying to make a has-permission command for my Discord bot, which takes two arguments: the user to check, and the permission to check for. You can see the code in the bot's GitHub repository (the config.json file is hidden due to it containing private information about my bot application).

Discord Screenshot: 不和谐截图

The bot just replies there was an error trying to execute that command! .

Console Screenshot:控制台截图

The console just says TypeError: member.hasPermission is not a function .

Is there any way around this? It seems like this is the only problem I am having making this command.

You need to use:

const member = message.mentions.members.first();

instead of:

const member = message.mentions.users.first();

as message.mentions.members.first() will be the first mentioned member in the message, and you need to use Member.hasPermission() . When using message.mentions.users.first().hasPermission() , you're using User.hasPermission() and you just can't.

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