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

£可爱£侵袭症+ 提交于 2021-01-28 19:48:50

问题


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: Discord Screenshot

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

Console Screenshot: 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.


回答1:


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.



来源:https://stackoverflow.com/questions/63420084/typeerror-member-haspermission-is-not-a-function-when-checking-permissions

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!