Skip to content
Puranode

Guide

How to Host a Discord Bot 24/7 Without a Laptop

To keep a Discord bot online 24/7 you need a machine that stays on and a supervisor that restarts the bot when it crashes and when the machine reboots. Reconnecting to Discord's gateway after a network drop is already handled by discord.py and discord.js. Everything around that is yours to get right: restarting without spending Discord's daily login allowance, keeping tokens out of repositories, sizing memory from measurement, keeping data safe across restarts, and calling AI models without a request hanging for minutes. This guide covers each, with Telegram alongside.

Published

FAQ

Frequently asked

Can I host a Discord bot 24/7 for free?

Yes, if you own a machine that stays on. Run the bot under systemd, Docker with a restart policy, or pm2, make sure it starts at boot, and test a crash and a reboot. You pay in electricity and in your time when something breaks. Paid hosting buys someone else's machine and supervision, not a different kind of bot.

Why does my bot go offline for a few seconds and then come back?

Usually that is the gateway working as designed. Connections are resumed after network drops, missed heartbeat acknowledgements and Reconnect events, and discord.py and discord.js handle all of it. Brief gaps are normal; long ones deserve a look at the logs.

Why did Discord reset my bot token?

One documented cause is the identify limit. A bot that starts 1,000 new gateway sessions in 24 hours, usually by crash-looping after login, has every session terminated and its token reset, and the owner is emailed. If the bot was not restarting repeatedly, check whether the token was ever pushed anywhere public, since GitHub reports Discord bot tokens it finds in public repositories to Discord.

Do I need the Message Content intent?

Only if the bot reads the text of other people's messages, as prefix commands and keyword triggers do. Slash commands do not need it, and even without it a bot sees its own messages, direct messages and messages that mention it. With fewer than 10,000 users you enable it yourself in the Developer Portal; beyond that, continued access needs a review.

Why is my Python bot's console empty when it is clearly running?

Output buffering. When stdout is not an interactive terminal, Python block-buffers it, so print output waits in a buffer and is lost if the process is killed. Run python -u, set PYTHONUNBUFFERED, or log through the logging module, whose default handler writes to stderr.

How do I stop AI replies timing out on Discord?

Defer the interaction within 3 seconds, then edit the reply in when the model finishes; the interaction token stays valid for 15 minutes. Give the model call its own timeout in seconds, because SDK defaults can run to minutes, and use an async client so the wait never blocks the bot's heartbeats.

Projects referenced

This guide names other people’s work. These are their own pages, so you get the current documentation rather than our summary of it.

  • Discord Gateway documentationThe source for heartbeats and resuming, the 1,000 identify limit and the token reset that follows it, the 120 events per 60 seconds send limit, sharding at 2,500 servers, and the privileged intent rules, including the 10,000 user threshold and the Message Content exceptions.
  • Discord interactions: receiving and respondingThe 3 second deadline for a first response, deferred responses, and the 15 minute interaction token that the AI section is built around.
  • Discord developer quick startWhere the Reset Token button lives, and Discord's own instruction never to check a bot token into version control.
  • Discord app verificationDiscord's article on the verification an app needs before it can grow past 100 servers, which the guide separates from privileged intent review.
  • discord.pyThe library whose run() reconnect behaviour, max_messages, member_cache_flags and chunk_guilds_at_startup options, and blocking FAQ the guide describes.
  • discord.js GuideThe makeCache and sweepers options the sizing section recommends for bounding memory in a discord.js bot.
  • Telegram Bot APIgetUpdates with its timeout and offset parameters, setWebhook with its ports, certificate upload and secret_token header, and the 24 hour retention of undelivered updates.
  • Telegram Bots FAQThe per-chat, per-group and broadcast sending limits quoted in the Telegram section.
  • BotFatherThe /token command for replacing a compromised Telegram token, and BotFather's warning that anyone holding a token can control the bot.
  • GitHub secret scanningLists Discord bot tokens as a partner pattern with push protection, which is why a token pushed to a public repository is reported to Discord.
  • systemdRestart=on-failure, the 100 ms default restart delay, and the start rate limiting that leaves a fast-failing unit stopped.
  • Docker restart policiesThe unless-stopped and always policies, and the rule that a policy only applies once a container has stayed up for 10 seconds.
  • PM2pm2 startup and pm2 save, the process manager route to bringing a Node bot back after a reboot.
  • npm ciThe lock-file install the guide recommends for Node bots, and how it behaves when package.json and the lock file disagree.
  • pip: repeatable installsPinning with ==, generating a pinned file with pip freeze, and hash-checking mode.
  • SQLiteWhy copying a live database file can produce a corrupt backup, and the VACUUM INTO and backup API alternatives the state section recommends.
  • Anthropic Python SDKThe example provider in the AI section: its 10 minute default timeout, two automatic retries, and reading ANTHROPIC_API_KEY from the environment.

Move the bot off your laptop

Hobby runs one bot on 0.5 vCPU and 512 MB, with auto-restart on crash, for €4.99 a month. Standard runs up to three bots on 1 GB for €9.99. VAT included, hosted in Helsinki.