简体   繁体   English

无法找到节点:使用 discord.js 的事件

[英]Cannot Find Node:Events with discord.js

I'm trying to make a discord bot using discord.js (I have discord.js installed) but for some reason, I keep getting this weird error.我正在尝试使用 discord.js(我安装了 discord.js)制作一个不和谐的机器人,但由于某种原因,我不断收到这个奇怪的错误。 I've looked through similar articles that address the same issue and suggested that I update my version of NodeJS to 16.6.0 or above (which I did) but have been unable to solve my issue.我浏览了解决相同问题的类似文章,并建议我将 NodeJS 版本更新到 16.6.0 或更高版本(我已经这样做了),但一直无法解决我的问题。 Any help would be much appreciated.任何帮助将非常感激。 Thank you.谢谢你。

code:代码:

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:错误:

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)

Read this . 读这个 This is definitely related to your Node.js version.这肯定与您的 Node.js 版本有关。 If you did upgrade, check the version: type node -v in your command prompt / terminal and see what version it shows.如果您确实升级了,请检查版本:在命令提示符/终端中键入node -v并查看它显示的版本。 Once I also had problems with node.js upgrades.曾经我也遇到过 node.js 升级的问题。

你能试试另一个吗

npx node .

I came to know you are using replit.我开始知道你在使用 replit。 So you may uninstall discord.js from the replit Packages (you can find it in left bar t).所以你可以从replit Packages中卸载discord.js(你可以在左栏t中找到它)。 And go to package.json change discord.js version 12.5.3 .并转到 package.json 更改 discord.js version 12.5.3 。 "discord.js": "^12.5.3", . "discord.js": "^12.5.3", . Then open shell and install discord.js@12.5.3 with npm install discord.js@12.5.3 .然后打开 shell 并使用npm install discord.js@12.5.3 After installing , run your code .安装后,运行您的代码。 It should work !它应该工作! Thank You谢谢你

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM