Skip to content
COL0

How to put a Python bot in production (Telegram, Discord and more)

Your bot works while your computer is on. To answer 24/7 it needs a server, a process that restarts itself and a safe way to store its keys.

Written by Victor Barrera

What you need before starting

  • A small Linux server (1 GB of RAM is usually enough) or a container service.
  • Your bot’s token, kept as an environment variable.
  • Your code with pinned dependencies.

The steps, in short

  1. Take keys out of the code: read the token from the environment; never leave it written in the repository.
  2. Prepare the server and create a virtual environment with the dependencies.
  3. Choose how to receive messages: polling to start, or a webhook with a domain and HTTPS if you expect high volume.
  4. Run the bot as a service (systemd) with Restart=always, so it comes back on its own if it fails or the server reboots.
  5. Keep logs and check them with journalctl; add error handling so an exception does not take the process down.
  6. Respect the platform’s limits (rate limits) and retry with increasing waits.
  7. Automate deployment: a workflow that updates the code and restarts the service.

Common mistakes

  • Running the bot with python bot.py inside an SSH session and losing it when you close it.
  • Using the same token in development and production: messages get stolen from each other.
  • Keeping important state only in memory and losing it on every restart.
  • Ignoring network errors and leaving the bot “hung” without reconnecting.

How we help

We leave your bot running 24/7, with automatic restart, logs and alerts if it stops responding.

Frequently asked questions

Polling or webhook?

With polling, your bot asks the platform whether there are new messages: it is simple and needs no domain. With a webhook, the platform sends each message to a public HTTPS URL: it is more efficient at scale, but requires a domain and a certificate.

Can I host a bot for free?

There are free plans with limits, but they often put the app to sleep or cap hours. For a bot that must always respond, a small VPS at a few dollars a month is more reliable.

Ready to publish your project?

Book your free 30-minute session and leave with a clear plan.

Book your free session