【发布时间】:2021-10-22 23:35:37
【问题描述】:
我试图让我的机器人检查每条消息,如果一个是命令,检查命令是否正确,如果不是,回复“无效命令,键入 z!help 以获取命令列表”。
我有什么:
fs.readdir("./commands/", (err, files) => {
if (err) return console.error(err);
files.forEach(file => {
if (!file.endsWith(".js")) return;
let props = require(`./commands/${file}`);
let commandName = file.split(".")[0];
console.log(`Attempting to load command ${commandName}`);
client.commands.set(commandName, props);
});
});
client.on('message', message => {
if (message.content.startsWith("z!")){
if (message.content !== commandName){
message.reply("Invalid command")
}
}
})
但我明白了
ReferenceError: commandName is not defined
感谢任何帮助!
【问题讨论】:
标签: node.js discord discord.js