Tutorial: create a Telegram bot and host it for free
To host a Telegram bot for free, you need three things: a token given by BotFather, about ten lines of code in Python or Node.js, and a machine that stays on for you. This tutorial follows these three steps in order, up to the bot’s first reply to the /start command. It uses polling: the bot needs neither a public address nor an HTTPS certificate.
ACLClouds teamPublished on November 21, 20268 min read
The essentials
BotFather creates the bot and gives its token with the /newbot command.
The code reads the token from the TELEGRAM_TOKEN environment variable, never hardcoded in a file.
In polling mode, the bot needs neither a public address nor an HTTPS certificate.
The ACLClouds Free plan runs 1 Node.js or Python bot with 315 MB of RAM, without a credit card.
A 409 Conflict error means that two copies of the bot are running with the same token.
ACLClouds · TutorialsTelegram
Your cookie choice
With your consent, we measure which ads bring us customers and how the site is used. Without it, nothing is measured and the site works exactly the same. You can change your mind at any time.Analytics and advertising, only with your consent. The site works the same without.
Tutorial: create a Telegram bot and host it for free
Create a Telegram bot with BotFather, write the minimal code in Python or Node.js, then host it for free 24/7: every step, with the common errors.
To host a Telegram bot for free, you need three things: a token given by BotFather, about ten lines of code in Python or Node.js, and a machine that stays on for you. This tutorial follows these three steps in order, up to the bot’s first reply to the /start command. It uses polling: the bot needs neither a public address nor an HTTPS certificate.
BotFather creates the bot and gives its token with the /newbot command.
The code reads the token from the TELEGRAM_TOKEN environment variable, never hardcoded in a file.
In polling mode, the bot needs neither a public address nor an HTTPS certificate.
The ACLClouds Free plan runs 1 Node.js or Python bot with 315 MB of RAM, without a credit card.
A 409 Conflict error means that two copies of the bot are running with the same token.
Create the bot with BotFather
In Telegram, open a chat with @BotFather, the official account that manages bots, and send /newbot. It asks for a display name, then a username that must end with bot, for example mon_premier_bot. It replies with the token, a series of digits and letters separated by a colon.
The token gives full control of the bot: do not put it in the code or in a screenshot.
If it has leaked, send /revoke to BotFather: the old token stops working and a new one is created.
In a group, a bot only receives commands by default. To read all messages, turn off privacy mode with /setprivacy.
The minimal code in Python
The most widely used library is python-telegram-bot. Create a requirements.txt file that contains the line python-telegram-bot, then a bot.py file. The program reads the token from the TELEGRAM_TOKEN environment variable, declares a /start command and starts receiving messages.
Create the application: Application.builder().token(os.environ["TELEGRAM_TOKEN"]).build().
Write an async function start(update, context) that replies with await update.message.reply_text("Hello").
Bind it to the command with add_handler(CommandHandler("start", start)), then finish with run_polling().
The package to install is called python-telegram-bot, while the import is written from telegram.ext import Application, CommandHandler.
The same bot in Node.js
In Node.js, Telegraf and grammY do the same job. With Telegraf, the package.json contains the telegraf dependency and a start script that runs node index.js. The index.js file fits in four lines.
Load the library: const { Telegraf } = require("telegraf").
Create the bot with the token read from the environment: const bot = new Telegraf(process.env.TELEGRAM_TOKEN).
Reply to /start with bot.start((ctx) => ctx.reply("Hello")), then run bot.launch().
Host the bot for free
The ACLClouds Free plan for bot hosting runs a Node.js or Python program around the clock, without a credit card. It is presented for Discord, but a Telegram bot in polling mode works there the same way: it is a program that opens an outgoing connection. When you order, choose Python or Node.js, then replace the sample project with your files from the Files tab or over SFTP on port 2222.
In the Startup tab, add an environment variable named TELEGRAM_TOKEN with the token from BotFather. The "Discord bot token" field stays empty.
Do not upload node_modules or .venv: the dependencies are installed on the server from requirements.txt or package.json.
To upload the files with FileZilla, follow the guide deploy a bot over SFTP.
Start and test
Start the bot from the console, then open the chat with your bot in Telegram and send /start. The reply arrives within a second or two. If nothing comes, the console shows the cause: read the first error line.
401 Unauthorized: the token is wrong or has been revoked. Copy it again from BotFather.
409 Conflict: another copy of the bot is already running with the same token, often on your computer. Stop it. If a webhook was ever set, delete it with the deleteWebhook method.
No module named telegram: the python-telegram-bot line is missing from requirements.txt. See the guide ModuleNotFoundError.
No message received in a group: privacy mode is on, only commands arrive.
What the Free plan allows
A Telegram command bot uses little: the Free plan is enough for it in most cases. Its limits are public, and the trade-off for being free is a renewal you do by hand.
1 bot per account, 315 MB of RAM, 0.25 vCPU and 715 MB of storage.
Free renewal every 4 days from the bot’s page. Without a renewal, the bot is suspended.
The bot is not put to sleep between two messages, and it restarts by itself after an unexpected stop.
Polling or webhook, send rate and memory: the guide Telegram bot 24/7 covers these choices in detail.
Frequently asked questions
Can a Telegram bot run on a plan meant for Discord?
Yes. The plan runs a Node.js or Python program: a Telegram bot in polling mode starts there like a Discord bot. Only the name of the token variable changes.
Do I need a domain name or an HTTPS certificate?
No, not in polling mode: the bot is the one that queries Telegram. A webhook, however, needs an HTTPS address reachable from the Internet.
Does the bot reply when my computer is off?
Yes. It runs on ACLClouds infrastructure. You just renew the Free plan for free every 4 days from the bot’s page.
Which library should I choose to get started?
python-telegram-bot in Python, Telegraf or grammY in Node.js. All three are documented and are enough for a command bot. Pick the language you already know.