Fixing "Cannot find module" and "ModuleNotFoundError" on your bot
Your bot ran perfectly on your own computer, and the moment you upload it, the console says it can't find something. This is the most common first-day problem with hosted bots, and it's nearly always one of a handful of causes.
Node.js: "Cannot find module"
The error looks like Error: Cannot find module 'discord.js' or Cannot find module './commands/ping'. Check these in order.
1. The dependencies aren't installed here. Your node_modules folder is huge and usually not uploaded, so the server has to install packages itself from package.json. Make sure that file is uploaded, and that it lists every package you use. If a package works locally only because you once installed it globally, it won't be in the file. Add it with npm install package-name on your computer, then upload the new package.json.
2. Letter case. Windows and macOS don't care whether you write ./Commands/Ping.js or ./commands/ping.js. The server does. If the folder is called commands and your code says Commands, you get exactly this error, and it's easy to miss because it worked at home. Match the case of every file and folder name precisely.
3. A wrong path. ./commands/ping is relative to the file that contains the require. Moving files around without updating the paths breaks it. Also check that the startup file in your server settings is the right one.
4. A related one: Cannot use import statement outside a module. You wrote import syntax but the project is set up for require. Either add "type": "module" to package.json, or switch the imports to require.
Python: "ModuleNotFoundError"
The error looks like ModuleNotFoundError: No module named 'discord'.
1. It's missing from requirements.txt. The server installs from that file. List every package your bot imports, one per line, for example discord.py and python-dotenv.
2. The package name and the import name differ. This catches people constantly:
| You install | You import |
|---|---|
discord.py | discord |
python-dotenv | dotenv |
pillow | PIL |
beautifulsoup4 | bs4 |
The file needs the left-hand name. The error message shows the right-hand one.
3. Running pip freeze blindly. pip freeze > requirements.txt writes every package on your computer, including things your bot doesn't use, some of which may not install on the server. Prefer a short file with only what you import.
Both languages: check the version
If a package needs a newer runtime than the server has, installation fails or the code breaks. Check which Node or Python version your server uses on its Startup settings and compare it with what you run at home.
After you fix it
Restart the bot and watch the console. If a different error appears, that's progress: the first one is gone. Read it from the top, as described in How to read your server logs.
For full walkthroughs, see Deploy a Node.js Discord bot and Deploy a Python bot. If the bot starts but then stops, Keep your bot online covers that.
Still stuck? Open a ticket on Discord - run /ticket in any channel, pick a department, and include your Server ID or Invoice ID so we can jump straight in.