找不到节点:不协调.js的事件



我正试图使用discord.js制作一个discordbot(我安装了discord.jss(,但由于某种原因,我一直收到这个奇怪的错误。我查阅了解决同一问题的类似文章,并建议我将NodeJS版本更新到16.6.0或更高版本(我确实做到了(,但一直无法解决我的问题。任何帮助都将不胜感激。非常感谢。

代码:

const Discord = require("discord.js")
const client = new Discord.Client()
client.on("ready", () => {
console.log('Logged in as', client.user.tag)
})
client.on("message", msg => {
if (msg.content == "ping") {
msg.reply("pong");
}
})
client.login(process.env.TOKEN)

错误:

Error: Cannot find module 'node:events'
Require stack:
- /home/runner/name_file/node_modules/discord.js/src/client/BaseClient.js
- /home/runner/name_file/node_modules/discord.js/src/index.js
- /home/runner/name_file/index.js
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:815:15)
at Function.Module._load (internal/modules/cjs/loader.js:667:27)
at Module.require (internal/modules/cjs/loader.js:887:19)
at require (internal/modules/cjs/helpers.js:74:18)
at Object.<anonymous> (/home/runner/name_file/node_modules/discord.js/src/client/BaseClient.js:3:22)
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 Module.require (internal/modules/cjs/loader.js:887:19)

我知道您正在使用replit。因此,您可以从replit软件包中卸载discord.js(您可以在左栏t中找到它(。然后转到package.json change discord.js 12.5.3."discord.js": "^12.5.3",版本。然后打开外壳并安装discord.js@12.5.3具有CCD_ 2。安装后,运行您的代码。它应该起作用!谢谢

阅读本文。这肯定与你的Node.js版本有关。如果您确实进行了升级,请检查版本:在命令提示符/终端中键入node -v,然后查看它显示的版本。有一次,我在升级node.js时也遇到了问题。

最新更新