javascript - 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):
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.
- Checking to see if the ‘Discord’ should be capitalised or not.
- Changing the version on the ‘version’ of my 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.
- Tweaking the code such that I provided an exact file location instead of just ‘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?
解决方案
因此,我不顾这个无用的社区,现在有了一个工作机器人,尽管我承认我刚刚找到了一个有效的指南(以前的指南没有,我仍然不知道为什么),然后复制了他们的代码。
该指南可以在这里找到:
https://www.digitaltrends.com/gaming/how-to-make-a-discord-bot/
也许将'discord.io'直接安装到与代码相同的文件夹中可能是修复?虽然我不确定如果摆弄目录不起作用,为什么会这样?
无论哪种方式,我希望这可以帮助任何有同样问题的人!
-奥利
推荐阅读
- javascript - 根据多个条件从数组中删除重复对象
- vb.net - 在 vb.net 中将文件作为 FormData 上传?
- java - 试图理解 Java 8 中的方法引用(将类方法分配给功能接口)
- amazon-web-services - AWS CLI 返回不存在这样的存储桶,但我可以在控制台中看到存储桶
- git - 获取当前分支上带有最新标签的提交哈希
- azure - 如何使用带有死信原因和错误描述的 Rest Api 向 Azure 服务总线订阅死信发送消息?
- google-cloud-storage - 使用 Cloud CDN 缓存的 Google 存储对象版本控制
- javascript - 如何使用 bot Discord 添加频道和类别
- python - 当列表包含多个子类时,mypy 抱怨 Sequence[Parent]
- javascript - 引导多选下拉更改值基于其他多选