【发布时间】:2019-01-18 07:15:49
【问题描述】:
我正在使用 Discord.js 为 Discord 编写一个机器人。在过去的一个月里,该机器人一直运行良好,过去几天我对代码所做的唯一更新是更新 Discord.js 和 Enmap。但是,现在当我尝试运行命令时(在此示例中它很有帮助),我收到此错误:
Error: Cannot find module './commands/help.js'
at Function.Module._resolveFilename (module.js:547:15)
at Function.Module._load (module.js:474:25)
at Module.require (module.js:596:17)
at require (internal/module.js:11:18)
at module.exports (/app/events/message.js:162:17)
at emitOne (events.js:116:13)
at Client.emit (events.js:211:7)
at MessageCreateHandler.handle (/rbd/pnpm-volume/6c985a92-4a9b-4fa1-
bea8-7452f0bbbcd9/node_modules/.registry.npmjs.org/discord.js/11.4.0/node_modules/discord.js/src/client/websocket/packets/handlers/MessageCreate.js:9:34)
at WebSocketPacketManager.handle (/rbd/pnpm-volume/6c985a92-4a9b-4fa1- bea8-7452f0bbbcd9/node_modules/.registry.npmjs.org/discord.js/11.4.0/node_modules/discord.js/src/client/websocket/packets/WebSocketPacketManager.js:103:65)
这是我的命令处理程序的外观(在我的主机器人文件中):
client.commands = new Enmap();
fs.readdir("commands/", (err, files) => {
if (err) return console.error(err);
files.forEach(file => {
if (!file.endsWith(".js")) return;
let command = `./commands/${file}`;
let commandName = file.split(".")[0];
client.commands.set(commandName, command);
console.log(`Loaded ${commandName}`);
});
});
这就是事件 message.js 的外观(此处包含冷却功能):
const args = msg.content.slice(prefix.length).trim().split(/ +/g);
console.log(args);
const command = args.shift().toLowerCase();
console.log(command);
const cmd = require(client.commands.get(command));
if (!cmd || cmd === null) return;
else {
var time = Date.now();
if (client.cd.has(msg.author.id)) {
var wait = client.cd.get(msg.author.id);
if (time < wait) {
msg.channel.send(new client.discord.RichEmbed().setColor(client.color).setDescription(`Please wait **${Math.ceil((wait - time)/1000)}** seconds before using another command!`)).then(msg => {msg.delete(2000).then(()=>{console.log("deleted")}).catch(error=> {console.error(error)})});
}
else {
client.cd.set(msg.author.id, Date.now() + (client.sec * 1000));
try {
cmd.run(client, msg, args);
}
catch (err) {
console.error(err);
}
}
}
else {
client.cd.set(msg.author.id, Date.now() + (client.sec * 1000));
try {
cmd.run(client, msg, args);
}
catch (err) {
console.error(err);
}
}
}
我所有的命令文件也以exports.run = (client, msg, args) =>开头
Node.js/Discord.js 是否有任何原因无法读取我的命令文件?感谢您的帮助!
【问题讨论】:
标签: node.js module compiler-errors discord.js