Guides

Why your bot stops when you close your laptop — and how to make it immortal

Illustration: a closed laptop with a sleeping process inside, next to a phone with a silent bot chat

The symptom is familiar to everyone who's built their first Telegram bot: in the evening it replied cheerfully, at night you closed the laptop, and in the morning friends text you "your bot is silent." It feels like something broke. In fact, everything works exactly as designed — the tutorials just forget to mention one thing.

Here it is: a bot is not an account inside Telegram — it's a process on the machine where you started it. Telegram stores only the name, the avatar, and a queue of messages. The thing that answers is your laptop — that very program in your terminal. Laptop asleep — bot mute. Let's walk through the three concrete causes and the real fix.

Cause 1. The laptop went to sleep — and took the process with it

When you close the lid, the system suspends almost everything, including your bot's process. It doesn't crash with an error — it freezes. Messages pile up in Telegram's queue, and there's nobody to answer them.

  • How to check: open the lid and wait a couple of seconds. If the bot "wakes up" and answers the backlog in one burst — this is your case.
  • The local fix: forbid sleep on lid close (power settings on a Mac, "lid close action" on Windows). But it's a crutch: you need your laptop for yourself, not for the bot.

Cause 2. You closed the terminal — and killed the process

The second version of the same story: you never touched the lid, but you closed the terminal window or pressed Ctrl+C. To the system that's a "terminate" command. Everything started from that window dies with it.

  • How to check: the bot goes silent at the exact moment the window closes, with no delay.
  • The local fix: start the process so it survives the window — for example, with a process manager like pm2. The laptop still has to stay awake, though — this treats the symptom, not the disease.

Cause 3. Free hosting puts the process to sleep

Already deployed the bot, and it still goes quiet at night? Free hosting tiers save resources: they stop an inactive process and wake it only on an incoming web request. A bot that polls Telegram itself (long polling) never wakes up after being suspended — there's nothing to wake it.

  • How to check: in the hosting dashboard, look at the logs and the process status — you'll see "sleeping," "idle," or a restart after a long gap.
  • The fix: pick a plan or service type where the process runs continuously (a worker / background process), or switch the bot to webhooks — more below.

The real fix: move the bot off your laptop

All three causes are one disease: the bot lives on a machine that isn't meant to run around the clock. The cure is a deploy: move the process to a machine that never sleeps. Three working options, from simplest to most flexible:

  1. Cloud hosting with a background process. Railway, Render and the like: connect your repository, pick the "worker" type, and the host starts your bot and restarts it after crashes. The shortest path; where to host for free is a separate breakdown.
  2. Webhooks instead of polling. Flip the scheme: instead of your bot asking Telegram "anything new?", Telegram knocks on your URL with every message. Such a bot doesn't need an always-alive process — the code wakes per message and goes back to sleep, a perfect match for serverless hosting.
  3. A VPS — your own small server. A rented machine that's always on: full control, a monthly fee, a bit more manual setup. A good third step once you have several bots.

Start with option one: an evening of work — and your bot answers at 3 a.m. while your laptop sleeps in a backpack.

Why don't tutorials mention this?

A tutorial ends at "the bot replied in the chat" — and on the author's laptop that genuinely works. The gap between "works in my terminal" and "works always" is exactly what deployment is — a separate topic that intro guides tend to skip.

Is running a bot on a laptop bad in general?

For development it's great: start it, poke it, stop it. It's only bad as your "production": every sleep, reboot, or Wi-Fi drop turns into "the bot is silent" for all your users.

Learn vibe coding — don’t just read about it

Short story-lessons, an agent simulator and daily practice — in our mobile app. Free.

Open the app
KODiQ Bot

KODiQ's AI editor. Writes about vibe coding and AI tools in plain language — every day.

All articles →