1. Home
  2. Guides
  3. Discord bots
Discord botsGuide

How to host a Discord bot 24/7

As long as your bot runs on your computer it is only online when you are. Hosting it on a server keeps it connected to Discord around the clock. These are the steps, using discord.js as the example.

  • 6 min read
  • 16 sections
Discord bots

In short

  • A bot on your computer is only online while you are; on a server it is online around the clock.
  • The token is the bot's password: do not push it to a repository or write it into the code.
  • Upload the files over FTP, paste the token in the panel, press Start and read the logs if something fails.

1. Create the application and get the token

In Discord's developer portal create an application, add a bot and copy its token. The token is the bot's password: whoever has it controls the bot, so do not push it to a repository or paste it in a chat.

If it leaks, generate a new one from the same portal; the old one stops working.

2. Prepare the project

Your project needs a package.json with its dependencies and a main file (for example index.js). Check that it starts on your computer with node before uploading it.

3. Pick the language and the plan

Choose your bot's language and the memory it needs. A small bot that answers commands uses little; one that keeps a lot in memory or serves many servers needs more.

4. Upload the files over FTP

Connect over FTP with the credentials from the panel and upload your project, package.json included. The panel installs the dependencies it declares.

5. Set the token and start

Save the token in the panel and read it in your code with process.env.DISCORD_BOT_TOKEN. The panel uses the main field in package.json or looks for index.js or src/index.js. If you need a different path, set it in the panel before pressing Start.

From the panel you can read the logs, which is the first place to look if something fails.

6. Maintain it

Restart the bot from the panel when you upload changes and watch the logs after each update. If you switch language later, remember the previous code is deleted: keep a copy on your computer.

7. Turn on the intents your bot uses

Discord doesn't send bots all the information by default. If your bot reads message text, the member list or presence, you have to turn on the matching intent in the developer portal, under Bot: Message Content, Server Members or Presence.

It's one of the most common mistakes: the bot connects and shows online, but doesn't respond to anything. If the code asks for an intent that isn't enabled in the portal, Discord rejects the connection and the error appears in the logs.

8. Invite it to your server with just the permissions it needs

In the developer portal, under OAuth2, generate an invite link with the bot and applications.commands scopes (the latter for slash commands). Tick only the permissions the bot really needs.

Giving it administrator is convenient, but if someone steals the token they'll have full control of your Discord server. The fewer permissions, the less damage it can do.

9. Sync the code from GitHub

Instead of uploading files over FTP every time, you can connect the bot to your GitHub repository from the panel settings. The panel downloads the code from the repository and, if it's private, uses a GitHub access token stored encrypted.

Updating the bot is then as simple as pushing your changes to GitHub and restarting it from the panel.

10. Pick the language version

In the settings you can choose the language version the bot runs on (for example, the Node.js or Python version). Use the same one as on your computer: a library can work on one version and fail on another.

For Rust and Go there's no version to choose: you upload the program already compiled for Windows (an .exe file) and the panel runs it.

11. Backups and scheduled restarts

If your bot stores data in files (an SQLite database, per-server settings), take backups from the panel. Your files are copied, without the dependencies that can be reinstalled.

You can also schedule restarts at whatever time you like. They don't replace fixing a bug, but they help if your bot builds up memory over the days.

12. Common problems

If the bot doesn't behave as expected, check this in order:

  • It doesn't connect: the token is wrong or was regenerated. Copy the current one from the portal and paste it in the panel.
  • It connects but doesn't respond: intents are missing in the portal or the bot lacks permission to read or write in that channel.
  • Slash commands don't show up: the bot has to register them on start and Discord can take a while to show them. Check you invited it with applications.commands.
  • It stops on its own: open the panel logs; the error that brings it down appears at the end.

13. When your bot grows

A bot in many Discord servers needs to split the work across several connections (shards). Discord requires it from 2,500 servers, and the main libraries such as discord.js or discord.py handle it almost on their own.

There are also rate limits: Discord caps how many requests a bot can make in a short time. Libraries respect them out of the box, but if your bot sends many messages in a row, you'll notice some are delayed. That's normal and not a hosting problem.

14. Register slash commands only when they change

Slash commands are registered with Discord. Many tutorials register them on every start, but Discord limits how many times a day they can be created, and a bot that restarts often can hit that limit.

It's better to register them with a separate script when you add or change a command, and have the bot only answer them on start.

15. Where to keep data

For small data, a file (JSON or SQLite) in the bot's folder works well and is included in the panel backups. For something bigger or shared by several bots, use an external database and keep its password like the token: out of the code.

16. Checklist before leaving it running

Before calling the bot done:

  • The token is in the panel, not in the code or the repository.
  • The intents the bot uses are enabled in the developer portal.
  • You invited it with just the permissions it needs and with applications.commands.
  • The language version in the panel matches the one on your computer.
  • Slash commands are registered with a separate script, not on every start.
  • Important data is included in backups or kept in an external database.
  • You know where to look at the logs if something fails.