简体   繁体   English

找不到 Discord 机器人的模块“discord.js”

[英]Can't find module 'discord.js' for Discord bot

Since I have a fair amount of free time on my hands I figured I'd set myself a project, so I decided to build a discord bot.由于我手头有相当多的空闲时间,我想我应该为自己设置一个项目,所以我决定构建一个 discord 机器人。 I may in the future make it more complicated but at the moment I just want to get it working, this is my code thus far (minus my token):我将来可能会使它变得更复杂,但目前我只想让它工作,这是我迄今为止的代码(减去我的令牌):

1

This code worked completely fine about an hour ago, then suddenly it didn't.大约一个小时前,这段代码运行得很好,然后突然就不行了。 I started randomly getting this error (I should make clear that I made no changes in the code to cause this issue. It just worked one minute, and then didn't the next):我开始随机收到此错误(我应该明确表示我没有对代码进行任何更改以导致此问题。它只工作了一分钟,然后没有下一分钟):

C:\Program Files\nodejs\node.exe .\index.js
Process exited with code 1
Uncaught Error: Cannot find module ‘discord.js’

I have tried the following:我尝试了以下方法:

  • Uninstalling discord.js, then reinstalling it.卸载 discord.js,然后重新安装。
  • Checking to see if the 'Discord' should be capitalised or not.检查“Discord”是否应该大写。
  • Changing the version on the 'version' of my package.json.在我的 package.json 的“版本”上更改版本。
  • Completely rewriting my code from scratch in a new file.在新文件中从头开始完全重写我的代码。
  • Reducing the code to just that first line of code.将代码简化为第一行代码。
  • Running Visual Studio Code in administrator mode.在管理员模式下运行 Visual Studio Code。
  • Tweaking the code such that I provided an exact file location instead of just 'discord.js'.调整代码,以便我提供准确的文件位置,而不仅仅是“discord.js”。

None of these have worked.这些都没有奏效。 I am basically brand new to coding (hence the very simple code) and just fancied messing around with it, but I have genuinely no idea what caused my issue or how to fix it as I have checked everything I can think of.我基本上是编码新手(因此代码非常简单)并且只是想弄乱它,但我真的不知道是什么导致了我的问题或如何解决它,因为我已经检查了我能想到的一切。

Any ideas?有任何想法吗?

So in raw defiance to this useless community, I now have a working bot, although admittedly I just found a guide that worked (previous ones didn't, I still don't know why), then copied their code.因此,我不顾这个无用的社区,现在有了一个工作机器人,尽管我承认我刚刚找到了一个有效的指南(以前的指南没有,我仍然不知道为什么),然后复制了他们的代码。
The guide can be found here:该指南可以在这里找到:

https://www.digitaltrends.com/gaming/how-to-make-a-discord-bot/ https://www.digitaltrends.com/gaming/how-to-make-a-discord-bot/

Maybe installing 'discord.io' directly into the same folder as the code might have been the fix?也许将“discord.io”直接安装到与代码相同的文件夹中可能是解决方法? Although I'm not sure why that would be it if fiddling with the directory didn't work?虽然我不确定如果摆弄目录不起作用,为什么会这样?

Either way, I hope this helps anyone with the same issue !无论哪种方式,我希望这可以帮助任何有同样问题的人!

-Ollie -奥利

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

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