How to run a Telegram bot on a server so that it works 24/7
A bot started on a laptop goes off together with the laptop. On a server it runs around the clock and comes back by itself after a failure. All it needs is the code in a repository.
What to prepare
- A GitHub repository with the bot's code. It may be private.
- A dependency file:
requirements.txtfor Python orpackage.jsonfor Node.js. - The bot token from @BotFather. It is best read in the code from an environment variable such as
BOT_TOKENand not kept in the repository.
How to start
- Open the bot hosting page and pick a plan. Mini is enough for most bots.
- When ordering choose the app Your Telegram bot.
- Give the link to the repository, the variables and, if needed, the start command, for example
python main.pyornpm start. - After the payment we clone the code, install the dependencies and start the bot as a system service.
What next
The bot's logs show in the panel. Push your changes to GitHub, update in one click in the panel, and the bot restarts with the new code. After a failure or a server reboot it comes back by itself.
If the bot needs a database or webhooks
The bot gets a whole server with root access. Next to it you can put PostgreSQL or Redis, open a port for webhooks and run a few more bots. The server has an address of its own and a free name on pirs.dev.
Questions
What does it cost to keep a bot on a server?
From $6.99 a month on the Mini plan: 1 GB of memory is enough for most bots.
Will it do for a Discord bot?
Yes. Any bot in Python or Node.js from GitHub runs.
Can I do without GitHub?
Yes. You have root access: upload the files over SFTP and start the bot yourself.
How do I update the bot?
Push the changes to the repository and update the bot in one click in the panel.
More in the help
- How to connect to a server over SSH, step by step
- How to reinstall the system on a server
- UFW blocked SSH: how to get back into the server
- An XFCE desktop on an Ubuntu server over RDP
- How to add an extra IP address to a server
- Signing in and protecting your account: e-mail, Google, Telegram, a code
- One-click apps: how to install one on a server
- Traffic and speed: what a plan includes
- Payment, renewal and auto-renewal of a server
- Which server to choose for your task
- Why a service shows another country for the server
- How to move to a higher plan and carry your data over
- Windows Server 2022 on a server: plans and connecting
- How to make a Minecraft server to play with friends
- How to put mods on a Minecraft server: Forge and Fabric
- How to make your own CS2 server to play with friends
- How to put n8n on your own server: no limits on runs
- PIRS partner programme: 20 % of payments, with no end date