`TypeError: member.hasPermission() is not a function` when checking permissions in discord.js(`TypeError: member.hasPermission() is not a function`在discord.js中检查权限时)
问题描述
我正在尝试为我的 Discord 机器人创建一个 has-permission 命令,该命令需要两个参数:要检查的用户和要检查的权限.您可以在 bot 的 GitHub 存储库 中查看代码(config.jsoncode> 文件被隐藏,因为它包含有关我的机器人应用程序的私人信息).
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).
不和谐截图:
机器人只是回复尝试执行该命令时出错!
.
控制台截图:
控制台只是说 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.
推荐答案
你需要使用:
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.
这篇关于`TypeError: member.hasPermission() is not a function`在discord.js中检查权限时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:`TypeError: member.hasPermission() is not a function`在disco


- 使用RSelum从网站(报纸档案)中抓取多个网页 2022-09-06
- 如何使用 JSON 格式的 jQuery AJAX 从 .cfm 页面输出查 2022-01-01
- Flexslider 箭头未正确显示 2022-01-01
- CSS媒体查询(最大高度)不起作用,但为什么? 2022-01-01
- addEventListener 在 IE 11 中不起作用 2022-01-01
- Css:将嵌套元素定位在父元素边界之外一点 2022-09-07
- Quasar 2+Apollo:错误:找不到ID为默认的Apollo客户端。如果您在组件设置之外,请使用ProvideApolloClient() 2022-01-01
- Fetch API 如何获取响应体? 2022-01-01
- 400或500级别的HTTP响应 2022-01-01
- 失败的 Canvas 360 jquery 插件 2022-01-01