Bots
How to host a Discord bot (discord.js and discord.py) and fix common errors
Hosting runs your bot all day so it doesn't depend on your own PC.
Before you upload
- Create your bot in the Discord Developer Portal and copy its token.
- Never put the token in your code or share it. Store it as an environment variable named something like TOKEN.
Node.js (discord.js)
- Upload your files, including package.json.
- Install dependencies with npm install.
- Set the start command, for example node index.js.
- Add your TOKEN as an environment variable and start the bot.
Python (discord.py)
- Upload your files and requirements.txt.
- Install with pip install -r requirements.txt.
- Set the start command, for example python bot.py.
- Add your token as an environment variable and start the bot.
Common errors
- "An invalid token was provided": the token is wrong, has spaces, or was reset. Copy a fresh token.
- "Used disallowed intents" or "Privileged intent not enabled": in the Developer Portal, open your bot page and turn on the intents your code uses (Message Content, Server Members or Presence).
- "Missing Permissions" (50013) or "Missing Access" (50001): give the bot the right permissions and move its role higher than the roles it manages.
- "Cannot find module" or "ModuleNotFoundError": the dependencies are not installed. Run npm install or pip install again.
- "EADDRINUSE": something is already using that port. Change the port in your code.
- Slash commands don't show: register them, and note that global commands can take a while to appear.