問題描述
我正在嘗試為我的 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中檢查權限時的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!