Learning objectives
After reading this article you will be able to:
- Understand why a bot drops when the PC or phone turns off
- Know the limits of running a bot on Android with Termux
- Compare PC, phone and hosting and pick for your case
Almost every Discord bot starts on its author's computer. You run node index.js, the bot comes online, and the job looks done. Then you close the laptop, the power blinks, or Windows restarts to update, and the bot vanishes from your server.
That is not a bug in your code. A bot is a process that has to run all the time, and that process only exists while the machine running it is on. There are three common ways to keep it alive: your PC, your phone with Termux, and hosting.
Why does the bot go offline when the PC turns off?#
The bot opens a WebSocket connection to the Discord Gateway and keeps it alive with periodic messages called heartbeats. According to the Gateway documentation, if heartbeats are not acknowledged the connection is treated as dead, and the client should close it and try to reconnect.
When the PC shuts down, the process dies with it. When it sleeps, the CPU stops and the network often drops, so the connection closes. In both cases Discord shows the bot as offline, and no command gets an answer until it is back.
Reconnecting is automatic only when the process is still alive (a short network drop, for example). If the process was terminated, someone has to start it again. Other causes are covered in why a Discord bot goes offline.
What is it like to run the bot on a PC?#
It is the simplest option and the best for development. You get logs in the terminal, restart with Ctrl+C, and debug easily.
For continuous use it has clear limits:
- Power: the PC must stay on and be set to never sleep.
- Network: internet outages or an IP change drop the connection for a while.
- Restarts: system updates reboot the machine, and the bot does not come back unless you set up
pm2or a startup task. - Shared use: the bot competes for CPU and memory with whatever else you do on the machine.
Even with pm2 and automatic startup, availability depends on your home, not on the bot. The power cost of this option is in how much it costs to host a Discord bot.
Can you run the bot on a phone with Termux?#
On Android, yes. Termux is a terminal emulator with a Linux environment, and you can install Node.js or Python in it. The basic flow:
pkg update
pkg install nodejs git
git clone https://github.com/your-user/your-bot.git
cd your-bot
npm install
node index.jsKeep the token in an environment variable or a .env file outside the repository, never in the code.
Three things matter:
- Where to install from: the project README recommends the F-Droid or GitHub builds. The Google Play build is experimental, has missing functionality and bugs, and the Termux app and its plugins must be installed from the same source.
- Android 12 or later: the project itself warns that Termux may be unstable, because Android kills "phantom" processes beyond 32 (the limit covers all apps combined) and processes using excessive CPU. The symptom is a
Process completed (signal 9)message in the terminal. - Battery saving: the system may suspend the app in the background. Turning off battery optimization and using the Termux wake lock helps but does not guarantee anything: there is a user report on Android 15 of processes killed anyway. Results vary by device and Android version.
A phone also has a practical limit: it must stay charging, on Wi-Fi, and not be used for anything else. It suits testing or a throwaway bot, not a community that expects answers at any hour.
What changes when you host the bot?#
Hosting means running the same code on a machine that is not yours, powered on all the time, in a datacenter with redundant power and network. The process no longer depends on your PC, your phone or your internet.
In practice:
- The bot stays online when you shut down your computer.
- Automatic restart after a crash usually comes built in; at home you would have to set it up yourself.
- Logs are reachable from anywhere.
- You pick the process memory instead of sharing your device's.
In exchange there is a monthly fee, and you deploy instead of running node index.js locally. There are two families: a VPS, where you administer the operating system, and hosting platforms, where you only upload code. To compare what each includes, see how to keep a Discord bot online 24/7. Typical limits of no-cost tiers are in limits of no-cost bot hosting.
PC, phone or hosting: which one?#
| Criterion | PC | Phone (Termux) | Hosting |
|---|---|---|---|
| Online with the device off | No | No | Yes |
| Survives sleep and power outages | No, unless configured | Unstable, depends on Android | Yes |
| Automatic restart | Only if you set it up | Only if you set it up | Usually included |
| Cost | Electricity | Battery and the device | Monthly fee |
| Best for | Developing and debugging | Quick tests, learning | A bot the community always uses |
There is no universal winner. Pick like this:
- Writing and testing the bot: use the PC.
- Just experimenting or learning away from the computer: a phone with Termux works, knowing it may drop.
- The bot serves people who expect answers at any hour: host it. Downtime usually costs more in complaints than the monthly fee.
How to do this on Square Cloud#
On Square Cloud the bot leaves your PC and your phone and runs in a container, in a Tier 3 datacenter with redundant power. Closing the laptop, a power cut at home or Android killing Termux no longer takes it down. The container stays on, with no sleep mode, and the application is never suspended for lack of traffic. If the process exits with an error, automatic restart, which is on by default for dashboard deploys, brings the bot back.
Swapping a local node index.js for a deploy is a short step. You upload the project as a ZIP in the dashboard, or use the CLI, GitHub or the VS Code extension, and the dashboard detects the main file and generates the configuration. The token goes in as an application environment variable, and the dashboard can import your .env. Your phone stays useful, now for following real-time logs in the mobile app instead of holding up the process.
A bot is a background application with a 256 MB RAM minimum, and it works with discord.js, discord.py, JDA, Discord.Net or any Gateway library. Hobby costs R$12.49 per month for 1 GB of RAM, paid by Pix or card. See what is included on Discord bot hosting and compare plans on pricing.
Bot hosting
Keep your bot online 24/7 with automatic restarts
FAQs
Can I run a Discord bot on my phone?
Yes, on Android with Termux and Node.js or Python installed. It works for testing, but Android can kill background processes, so availability is uneven.
Does my bot go offline when I turn off my PC?
Yes. A bot is a process that keeps a connection open to the Discord Gateway. When the process stops, the connection drops and the bot shows as offline until you start it again.
Does suspending the PC or closing the laptop lid take the bot down?
Usually yes. In sleep the CPU stops and the network often drops, so the Gateway stops getting heartbeats and treats the connection as dead. Setting the power plan to never sleep avoids it, at the cost of keeping the machine on.
Do I have to pay to keep a bot online 24 hours a day?
Someone has to keep a machine running: you at home, paying for power and accepting outages, or a provider charging a monthly fee. No-cost tiers exist, but they usually come with limits on hours or RAM, or with suspension.
More in Bots
See all 33 articles- How much does it cost to host a Discord bot?The cost of hosting a Discord bot depends on RAM, uptime, database and outside services. Learn how to estimate your own bill and where the money goes.
- Why your Discord bot keeps going offline (and how to fix it)A Discord bot goes offline when the process dies, the token is invalid, an intent is disabled or memory runs out. Learn to diagnose each cause and fix it.
- How to host a Telegram bot 24/7To keep a Telegram bot online 24/7, run its process on an always-on server using long polling or a webhook. See working code and the common errors.
- Free bot hosting: sleep, limits and hidden trade-offsFree bot hosting often puts your process to sleep, caps monthly hours or disappears. See the real limits of Render, Oracle Cloud, Glitch and Heroku.