`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


基础教程推荐
- Vue 3 – <过渡>渲染不能动画的非元素根节点 2022-01-01
- 直接将值设置为滑块 2022-01-01
- 如何使用TypeScrip将固定承诺数组中的项设置为可选 2022-01-01
- 用于 Twitter 小部件宽度的 HTML/CSS 2022-01-01
- 如何使用JIT在顺风css中使用布局变体? 2022-01-01
- Chart.js 在线性图表上拖动点 2022-01-01
- Electron 将 Node.js 和 Chromium 上下文结合起来意味着 2022-01-01
- html表格如何通过更改悬停边框来突出显示列? 2022-01-01
- 自定义 XMLHttpRequest.prototype.open 2022-01-01
- 我可以在浏览器中与Babel一起使用ES模块,而不捆绑我的代码吗? 2022-01-01