簡體   English   中英

用 index.js 替換 main.js,錯誤:ENOENT?

[英]Replacing main.js with index.js, Error: ENOENT?

我很困惑為什么這個機器人現在可以運行,我認為這是因為我沒有“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
 

Package.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"
    }
}

文件:

https://i.stack.imgur.com/FptiD.png

這是一個鏈接,可幫助您將索引更改為 repli 中的其他內容

https://replit.com/talk/ask/Is-it-possible-to-changedeleted-indexjs/43264

@HDM91

新錯誤:

(node:1059) UnhandledPromiseRejectionWarning: Error [DISALLOWED_INTENTS]: Privileged intent provided is not enabled or whitelisted.
    at WebSocketManager.createShards (/home/runner/DwaCraft-Ticket-bot/node_modules/discord.js/src/client/websocket/WebSocketManager.js:258:15)
(node:1059) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
(node:1059) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

package.json文件中的 "scripts" => "start" 中將名稱文件從main.js更改為index.js ,然后點擊npm start 請記住從 main.js文件所在的文件folder運行script並重命名文件

{
    "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 index.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"
    }
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM