问题描述
我正在尝试为我的 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中检查权限时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!