我很困惑为什么这个机器人现在可以运行,我认为这是因为我没有“index.js”我使用“main.js”我如何才能从“main.js”切换到“index.js”。杰”?
我将添加所有可能帮助您发现错误的主要代码:D
这是“main.js”中的代码:
const { Client, Collection, Intents } = require('discord.js');
const client = new Client({ disableMentions: 'everyone', partials:
['MESSAGE', 'CHANNEL', 'REACTION'], ws: { intents: Intents.ALL } });
client.commands = new Collection();
client.aliases = new Collection();
['command', 'event'].forEach(handler => {
require(`./handlers/${handler}`)(client);
});
client.login(process.env.BOT_TOKEN);
错误:internal/fs/utils.js:269
throw err;
^
Error: ENOENT: no such file or directory, open '/home/runner/DwaCraft-Ticket-bot/index.js'
at Object.openSync (fs.js:462:3)
at Object.readFileSync (fs.js:364:35)
at Object.<anonymous> (/run_dir/interp.js:195:19)
at Module._compile (internal/modules/cjs/loader.js:999:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1027:10)
at Module.load (internal/modules/cjs/loader.js:863:32)
at Function.Module._load (internal/modules/cjs/loader.js:708:14)
at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:60:12)
at internal/main/run_main_module.js:17:47 {
errno: -2,
syscall: 'open',
code: 'ENOENT',
path: '/home/runner/DwaCraft-Ticket-bot/index.js'
}
repl process died unexpectedly: exit status 1
包.json:{
"name": "ticket-bot",
"version": "1.0.0",
"description": "A simple ticket bot",
"main": "main.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "node main.js"
},
"author": "hamoodi",
"license": "ISC",
"dependencies": {
"better": "^0.1.0",
"cpu-stat": "^2.0.1",
"discord.js": "^12.5.3",
"dotenv": "^8.6.0",
"express": "^4.17.1",
"moment": "^2.29.1",
"os": "^0.1.2",
"sourcebin_js": "0.0.3-ignore"
}
}
文件:/image/FptiD.png
最佳答案
如下链接所述,您可以创建一个 .replit 文件,并在其中放入
运行=“Node [文件].js”
并将 [file] 替换为 main。
https://replit.com/talk/ask/Is-it-possible-to-changedeleted-indexjs/43264
关于javascript - 用 index.js 替换 main.js,错误 : ENOENT?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/70232694/