首页 > 解决方案 > 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. 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:

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?

标签: javascript

解决方案


因此,我不顾这个无用的社区,现在有了一个工作机器人,尽管我承认我刚刚找到了一个有效的指南(以前的指南没有,我仍然不知道为什么),然后复制了他们的代码。
该指南可以在这里找到:

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

也许将'discord.io'直接安装到与代码相同的文件夹中可能是修复?虽然我不确定如果摆弄目录不起作用,为什么会这样?

无论哪种方式,我希望这可以帮助任何有同样问题的人!

-奥利


推荐阅读