我目前正在使用Discord.js机器人,并且正在尝试编写一个系统,其中只有JSON中的给定ID才能执行命令。我不知道如何在if
语句中查询它。
if (message.author.id === config.admin) {
if (cmd === 'mode') {
let mode = args[0];
if (mode === 'maintenance') {
bot.user.setActivity(config.maintenanceGame);
config.mode = 'maintenance';
const embed = new Discord.RichEmbed()
.setAuthor("Gorded Media Ltd. - Maintenance", 'http://imageurl/logo.png')
.setColor(color.red)
.setDescription("The mode was set to `Maintenance`. All users can't use the commands in this mode.");
message.channel.send(embed);
}
if (mode === 'online') {
bot.user.setActivity(config.defaultGame);
config.mode = 'online';
const embed = new Discord.RichEmbed()
.setAuthor("Gorded Media Ltd. - Maintenance", 'http://imageurl/logo.png')
.setColor(color.lime)
.setDescription("The mode was set to `Online`. All users can use the commands in this mode.");
message.channel.send(embed);
}
console.log(`[` + date + `] ` + config.consoleprefix + ` User ${message.author.tag} set the mode to ${config.mode}`);
}
} else {
message.channel.send(no_perms)
}
这是config
中解析的JSON文件的结构:
"admin": [
"Discord Client ID",
"Discord Client ID",
"Discord Client ID"
]
答案 0 :(得分:0)
您不能检查message.author.id
是否等于config.admin
,因为那是一个数组。
但是,您可以使用Array.includes()
检查该数组是否包含ID:
if (config.admin.includes(message.author.id)) {...}