首页 > 解决方案 > `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

有没有办法解决?似乎这是我在执行此命令时遇到的唯一问题。

标签: javascriptnode.jsdiscorddiscord.js

解决方案


你需要使用:

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(),但不能。


推荐阅读