Moving a Telegram bot from PythonAnywhere, Replit, Railway or your PC is copying its files, pasting the same token, switching it to polling if it used a webhook, and starting it here once the old copy is stopped. The token stays the same, so the bot keeps its @username, its chats and its users. The steps:
- Get a bot plan set up for Telegram, with the language your bot is written in.
- Copy your files in Files (zip, upload, Unzip), over SFTP, or from Git, with
requirements.txtorpackage.json. - Set the Entry file and Runtime on the Bot page, pane Code.
- Paste the token on the Bot page, pane Telegram, and click Connect.
- Import your other settings with Paste a .env file on the Environment pane.
- If your bot used a webhook, change it to polling.
- Stop the old copy, press Start here, and watch Console until your bot logs in.
Each step is explained below.
Before you start
- Gather the bot's code and its data files (SQLite files, JSON files, saved settings) in one folder. From a host, download them as a zip or copy them from its file browser.
- Note every setting the old host gave your bot: its
.envfile or the variables you set in its dashboard. - Plan to stop the old copy right before you start the new one. Telegram lets only one copy of a bot ask for messages: two copies push each other out with
409 Conflict.
1. Get a plan set up for Telegram
On Telegram bot hosting, click Create Server on a plan, answer What is your bot for? with Telegram, and pick your bot's language: Node.js, Python, Java, C# (.NET), Bun, Deno, Go or Rust. STARTER (0.5 GB) is enough for most bots: see python-telegram-bot vs aiogram on PlayNHost for the memory we measured.
Already have a bot plan set up for Discord? On the Bot page, pane Discord, card What is this bot for?, choose Telegram and confirm with Switch. Wrong language? On the pane Code, click Change what runs next to Runtime.
2. Copy the files
- Small bot: zip the folder, upload the zip in Files, tick it and click Unzip.
- Big folder: use SFTP. SFTP details in Files gives the address; you sign in with your panel password.
- Code on GitHub: connect the repository instead, and upload only your data files. See How to deploy and update your bot from GitHub.
Leave out venv, .venv, __pycache__ and node_modules: the server installs packages itself. Your main folder here is /home/container. If your code opens data files by a full path from the old host (such as /home/yourname/mybot/data.db), change it to a path relative to the main folder. More: How to upload your bot code.
3. Packages and entry file
On the old host you may have installed packages by hand in a console. Here they come from a file:
- Python: a
requirements.txtwith one package per line, for examplepython-telegram-botoraiogram. Write in the names of the packages your code imports. Another file name or folder? Set it under Requirements file on the Settings card of the Code pane. - Node.js and Bun: your
package.jsonwith itsdependencies.
On Python, Node.js and Bun the packages install on the first start. After that they install again only when you change them (the package list, the package file or the runtime version), when node_modules is missing, or once a day. In between, Console says:
[PlayNHost] Packages are up to date. They install again when you change them, or after a day.
On the Bot page, pane Code, card How it runs, set Entry file to the file your old host started (for example main.py or src/index.js; bot.py and index.js are the defaults) and pick the same Runtime version. Click the Save button next to each field you change. Details per language: Python, Node.js.
4. The token
- On the Bot page, pane Telegram, paste the bot's token and click Connect. The panel checks it with Telegram and shows your bot's @username. Lost it? In @BotFather send
/mybots, choose your bot, then API Token. - Your code gets the token as
TELEGRAM_BOT_TOKEN, and also asBOT_TOKEN,TOKEN,TELEGRAM_TOKENandTELOXIDE_TOKEN. If your code reads another name, change that line to one of these. - If the token is written in your code or in a
config.json, replace it with the environment variable, for exampleos.environ["TELEGRAM_BOT_TOKEN"]in Python orprocess.env.TELEGRAM_BOT_TOKENin Node.js. Delete it from any.envfile you uploaded.
5. The other settings
- Open the Environment pane and click Paste a .env file.
- Paste your old
.envor the variables from your old host's dashboard. The token line is marked Skipped with Your Telegram token goes on the Bot page, Telegram, so that line is skipped. Your code reads it as TELEGRAM_BOT_TOKEN, and also as BOT_TOKEN, TOKEN, TELEGRAM_TOKEN and TELOXIDE_TOKEN. - Check the list (names that look like secrets get a Secret badge) and click the import button, for example Import 3 variables.
Using python-dotenv? Variables from Environment are already in os.environ, and load_dotenv() does not overwrite them. Had a MySQL database? Create one on the Databases page: How to use a database with your bot.
6. From webhook to polling
Some hosts run a bot on a webhook, for example through a web app on PythonAnywhere. Here your bot uses long polling: it asks Telegram for new messages and needs no address of its own. A webhook needs a public HTTPS address, which these plans do not include yet. Change the start of your bot:
| Library | Remove | Use |
|---|---|---|
| python-telegram-bot | application.run_webhook(...) | application.run_polling() |
| aiogram 3 | The aiohttp web app with SimpleRequestHandler | await dp.start_polling(bot) |
| pyTelegramBotAPI | bot.set_webhook(...) and the Flask route | bot.infinity_polling() |
| grammY | webhookCallback(bot, ...) | bot.start() |
| Telegraf | bot.launch({ webhook: ... }) | bot.launch() |
A small web server that only kept the bot awake on the old host is not needed here: the bot runs all the time.
The webhook stays set on your bot at Telegram until something removes it. python-telegram-bot and grammY remove it themselves when polling starts. With other code, the Telegram pane shows A webhook is set on this bot: click Remove webhook and confirm. The messages waiting are kept, so your bot fetches them here.
7. Switch over
- Stop the bot on the old host: an always-on task or scheduled task on PythonAnywhere, a deployment on Replit or Railway, or the terminal window or script on your PC.
- Press Start here and watch Console until your bot logs in. Print a line like
Logged in as @your_botwhen it is ready: the chip on Overview then turns to Online in Telegram. - Send your bot a command in Telegram. Then cancel the old host.
If something does not work
- Your bot is running somewhere else too above the console: the old copy is still running. Stop it, then restart here. See Fix Telegram bot 409 Conflict.
- A webhook is set on your bot: click Remove the webhook, then restart.
- A wrong file name, a wrong language or a missing package shows in the first seconds of the console, often as a banner. See Why your bot keeps stopping.
- The bot starts but has lost its data: check the data files kept the same folder structure, and that your code opens them by a path relative to
/home/container.



