[英]How can I owner lock this command in discord.js v12?
我正在尝试制作这个命令,所以只有我可以运行它,到目前为止还没有运气。
client.on("message", message => {
const args = message.content.slice(config.prefix.length).trim().split(/ +/g);
const command = args.shift().toLowerCase()
if (command === "test") {
console.log((chalk.yellow)`You ran a command: test`)
message.channel.send('test')
}
});
我尝试使用
if (!message.author.id === config.ownerID) return;
和
if (message.author.id !== config.ownerID) return;
当我使用第一个时,命令有效,但每个人都能运行它,而当我使用第二个时,根本没有人能够运行它。 我没有收到任何错误日志或崩溃。 有人知道正确的代码吗?
正如我在上面的评论中提到的,第一个肯定是不正确的,因为您正在使用逻辑 NOT 运算符 ( !
) 将message.author.id
转换为 boolean。 如果config.ownerID
是字符串,您的第二次尝试可能会起作用,但您不能将字符串与数组进行比较。
如果你的config.ownerID
是一个 ID 数组,你可以使用includes()
方法来检查message.author.id
是否包含在给定的数组中:
if (config.ownerID.includes(message.author.id)) return
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.