[英]How do I only allow a command to be toggled by users with certain permissions?
我编写了一个可以格式化文本的机器人 - 我需要它以便不仅仅是随机数可以访问命令。 这是我的代码 - 它不会引发任何错误
try {
if(message.member.guild.me.hasPermission('ADMINISTRATOR')) {
if (args[0] === 'off') {
christian[message.guild.id] = false
} else if (args[0] === 'on') {
christian[message.guild.id] = true
}
message.channel.send(`Christian Mode ${christian[message.guild.id] ? 'Active' : 'Inactive'}`)
return christian
} else {
message.channel.send('You do not have permission to use that command!')
}
} catch (error) {
console.log('Permission Error')
}
注意:通过说 =Christian on/off 这个函数有效,命令被切换回 index.js (main)。
message.member.guild.me.hasPermission('ADMINISTRATOR')
正在检查机器人的权限,而不是命令执行者的权限。 在message.member
上调用GuildMember#hasPermission()
(参见Message#member
)。
例如...
if (!message.member.hasPermission('ADMINISTRATOR')) {
// return an error to the user (and actually return)
}
// continue with command code
注意: Discord.js 文档超链接适用于最近发布的 v12。 如果您的 Discord.js 不是最新的,请切换到页面顶部的正确版本以获取准确信息。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.