javascript - `TypeError: member.hasPermission() is not a function`在discord.js中检查权限时
问题描述
我正在尝试为我的 Discord 机器人创建一个has-permission命令,该命令需要两个参数:要检查的用户和要检查的权限。您可以在机器人的 GitHub 存储库中看到代码(该config.json
文件由于包含有关我的机器人应用程序的私人信息而被隐藏)。
不和谐截图:
机器人只是回复there was an error trying to execute that command!
。
控制台截图:
控制台只是说TypeError: member.hasPermission is not a function
。
有没有办法解决?似乎这是我在执行此命令时遇到的唯一问题。
解决方案
你需要使用:
const member = message.mentions.members.first();
代替:
const member = message.mentions.users.first();
asmessage.mentions.members.first()
将是消息中第一个提到的成员,您需要使用Member.hasPermission()
. 使用时message.mentions.users.first().hasPermission()
,您正在使用User.hasPermission()
,但不能。
推荐阅读
- mysql - MySQL:BTREE 慢速索引路径(表大小:723704015 行)
- python - 创建一个函数,该函数接收名称为数组的字符串,然后打印每个元素 [python]
- node.js - TypeError:Router.use() 需要一个中间件函数,但有一个未定义的
- c# - 使用 iTextSharp 将图像插入 PDF 表单
- linux - bash 中过度设计的 checkroot
- java - swapWords 方法不返回修改后的 ArrayList
在爪哇 - android - 颤振:图像 BoxFit.cover 在堆栈中不起作用
- twilio - 通过 Twilio 获取 API
- html - thead 和 tbody 之间的边框和边距
- java - 在java中合并两个排序数组