在discord.js中检查权限时,"TypeError:member.hasPermission()不是函数" [英] `TypeError: member.hasPermission() is not a function` when checking permissions in discord.js

查看:52
本文介绍了在discord.js中检查权限时,"TypeError:member.hasPermission()不是函数"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试为Discord机器人发出 has-permission 命令,该命令带有两个参数:要检查的用户和要检查的权限.您可以在机器人的GitHub存储库( config.json 文件被隐藏,因为它包含有关我的bot应用程序的私人信息.

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屏幕截图:

Discord Screenshot:

该机器人只是回复尝试执行该命令时出错!.

控制台屏幕截图:

控制台仅显示 TypeError:member.hasPermission不是函数.

有什么办法解决吗?看来这是我执行此命令的唯一问题.

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

推荐答案

您需要使用:

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

代替:

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

作为 message.mentions.members.first()将是消息中最先提到的成员,并且您需要使用 Member.hasPermission().使用 message.mentions.users.first().hasPermission()时,您使用的是 User.hasPermission(),但是不能使用.

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.

这篇关于在discord.js中检查权限时,"TypeError:member.hasPermission()不是函数"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆