A Discord app has to hold an open connection to Discord to receive events. Close your laptop and that connection goes with it. Nothing is broken and there is nothing to fix in your code: the app needs to run somewhere that stays awake, which means a machine that is not yours.
That is the entire problem. Everything below is about where to put it.
Why your own machine does not work
People try three things first, and all three fail in the same way. Leaving the laptop open works until it sleeps, updates, or moves. A Raspberry Pi at home works until the power blips or your ISP rotates your address. A free tier that sleeps after inactivity works until the app is idle for fifteen minutes, which for most apps is most of the night.
The common thread is that a Discord gateway connection is not a request that finishes. It is a socket held open for as long as the app is alive, and anything that suspends the process drops it.
Why serverless is the wrong shape
Serverless functions are excellent at a specific job: run when called, then stop. A gateway app is the opposite: it is never called, it listens. There is no HTTP request to trigger the function and nothing to keep it warm between events.
You can force it with a scheduled ping every few minutes, and people do. It is fragile, it wakes the app on a timer rather than on events, and you end up paying for invocations that exist only to prevent a shutdown. If you have written a cron job whose only purpose is to keep your own app alive, that is the signal you want a process instead of a function.
What the options actually cost
Prices move, so treat these as shapes rather than quotes. What matters is what you are buying with the money.
| OPTION | ROUGHLY | THE CATCH |
|---|---|---|
| Free tier with sleep | $0 | Sleeps when idle, which is when most apps are needed least and noticed most |
| A VPS you administer | $4 to $6 | You own the OS, the updates, the process manager and the 3am restart |
| Managed app hosting | $3 to $12 | Less control over the machine, no machine to maintain |
| A spare machine at home | $0 plus power | Your power, your network, your uptime |
A VPS is the honest default if you enjoy administering a server. You get a whole Linux box for the price of a coffee. You also get everything that comes with a whole Linux box: keeping the kernel patched, configuring systemd or pm2 so the app restarts on crash and on reboot, and noticing when it has quietly stopped.
Managed hosting trades that away. You do not choose the base image and you do not get root, and in exchange nobody has to remember what a process manager is.
What "24/7" actually requires
Staying online is not one feature, it is four. Whichever option you pick, check it does all of these, because a host that does the first and not the rest will still drop your app.
- 01It never sleepsNo idle timeout, no cold starts, no keep-alive ping to write yourself.
- 02It restarts on crashApps crash. An unhandled rejection at 4am should come back by itself, not wait for you.
- 03It survives the machineHardware fails. Something has to notice and rebuild the process elsewhere.
- 04It tells you what happenedLogs you can read after the fact. An app that died silently is an app you debug twice.
Getting the token right
The single most common reason a bot runs locally and dies once deployed is the token. Your .env file is not deployed with your code, and it should not be. The token goes into the host’s environment variables instead.
If the app starts and immediately exits with a login error, that variable is missing or stale. It is the first thing to check and it is right at the top of the logs.
While you are in the Developer Portal, turn on the intents your code uses. An app requesting the message content intent without enabling it fails to connect, with an error that does not obviously say so.
How much memory an app needs
Less than people provision. A discord.js bot with a handful of commands sits comfortably under 200MB. discord.py is similar. You only need more when you are caching a lot of guild state, processing audio, or running a headless browser. Chromium alone is around 400MB once a page loads.
Sharding is a separate question and it arrives later than most people expect. Discord requires it at roughly 2,500 guilds. Below that, one process is simpler and easier to reason about.
The short answer
Put the app on something that stays awake, restarts it when it crashes, and keeps its token out of your repository. A VPS does this if you are willing to run it. Managed hosting does it if you are not.
Spocket is the managed version of that, from $3/mo, deployed by asking your AI editor rather than by opening a panel. If you already have a bot in a folder, that is the whole setup.