Asking an AI assistant for a Discord bot is one of the quickest wins there is. Describe what it should do, and a minute later you have a bot.js or bot.py that answers commands, welcomes new members or posts a daily reminder. You run it, it comes online in your server, and it works.
Then you close your laptop, and the bot goes offline.
That is not a bug in the code. A Discord bot is a program that has to keep running, and right now it runs on your laptop. This guide explains why bots are different from websites, the honest options for hosting one, and how to have your assistant put it on a server and keep it running without you touching a terminal.
Quick answer
A Discord bot that reads messages or reacts to events keeps a connection open to Discord the whole time it is online. So it needs somewhere that runs a program all day, every day: a server, not a website host.
Your options, from most hands-on to least:
- A small virtual server (VPS) is the cheapest in money, a few dollars a month, and you install, update and restart everything yourself.
- A worker or container platform runs the bot for you once you package it with the platform's configuration.
- Server4Agent lets the assistant that wrote the bot set it up too. It creates a project on a server, installs what the bot needs, uses the token you stored in Secrets, and starts the bot as a background process that comes back after a restart. The bot needs no public address, so the project stays private.
Why a bot is not a website
Discord gives an app two ways to receive what happens in a server. By default, an app receives interactions over a Gateway connection: a WebSocket the bot opens to Discord and holds open. Messages, members joining, reactions and presence updates all arrive over the Gateway. The alternative is an HTTP endpoint that Discord calls for interactions such as slash commands and button clicks.
That split decides where the bot can live:
- A bot that only answers slash commands can use the HTTP endpoint. It behaves like a small web API, so a serverless function can host it, because nothing has to stay running between commands.
- A bot that reads messages, welcomes members, moderates or keeps state between events needs the Gateway, which means a process that never stops. Most bots an assistant writes from a casual description are this kind, because libraries like discord.js and discord.py use the Gateway by default.
Other chat platforms work the same way. A Telegram bot either long-polls for updates or receives webhooks, and a Slack app either holds a Socket Mode connection or receives events over HTTP. In each case the always-connected mode is the easier one to write and the one that needs a server.
Your hosting options
| Option | What it costs | What you do yourself | Good fit when |
|---|---|---|---|
| Your own computer | Nothing | Keep it on and awake | You are testing |
| A VPS | A few dollars a month | Set up Linux, install the runtime, keep the bot running, apply updates | You are comfortable on a command line |
| A worker or container platform | A small monthly fee or usage | Package the bot with the platform's config, connect a repository | You already use that platform |
| Vercel Daemons (public beta) | Within plan quotas | Write a Dockerfile and a vercel.json entry, deploy to production | Your team already ships on Vercel |
| Server4Agent | A free plan to start, then usage under a budget cap | Create the bot in Discord's portal and store its token | You want the assistant to do the rest from the chat |
A word on "free 24/7 hosting": a bot that never stops uses a computer every hour of the month, so truly free always-on hosting is rare. Free tiers usually put idle services to sleep or cap the hours, and a sleeping bot is an offline bot. Check what a free tier does when nothing is happening before you rely on it.
Step by step: from chat to a bot that stays online
This assumes you have connected Server4Agent to your AI assistant. If not, the integrations page has the steps for each app and takes a couple of minutes.
1. Create the bot in Discord
In the Discord Developer Portal, create a new application, open its Bot page and reset the token to reveal it. Copy the token somewhere safe for the next step. If the bot needs to read what people write, turn on the Message Content Intent on the same page. Then use the application's install link to add the bot to your Discord server.
2. Store the token in Secrets, not in the chat
Open Secrets in the Server4Agent dashboard and add the Discord bot token preset, which saves it as DISCORD_BOT_TOKEN. Values in Secrets are write-only: no tool returns them, and the bot reads the token from its environment when it starts. Pasting the token into a chat would leave it in the conversation's history, which is a habit worth avoiding with any key.
3. Ask for the bot
Describe it the way you would to a person, and say where the token is:
> "Build a Discord bot for our community server. When someone joins, post a welcome in #introductions with links to the rules. Add a /standup command that collects replies until 10:30 and posts a summary. The token is in Secrets as DISCORD_BOT_TOKEN. Run it on my server and keep it running."
The assistant creates a project, writes the code, installs the library, attaches the secret to the project and starts the bot as a named background process. Then it reads the bot's log to confirm it connected, and tells you so. Nothing is deployed to a public URL, because a Gateway bot does not need one: it makes the connection to Discord, not the other way round.
4. Change it in the same chat
"Make the welcome message mention the event calendar" is a one-line request. The assistant edits the code and restarts the bot. If something goes wrong, ask "is the bot running?" and it will read the log and tell you what the bot last said.
Keeping it online
- Restarts. A bot started this way comes back by itself when the server restarts. A crash inside the bot is a different thing: ask the assistant to start it with a small loop that restarts it after a crash, such as
while true; do node bot.js; sleep 5; done. - Reconnects. Discord closes Gateway connections from time to time. discord.js and discord.py reconnect on their own, so let the library handle it.
- One copy only. Two running copies with the same token both answer every message, which looks like the bot replying twice. Before moving a bot from your laptop, stop the copy there.
- Logs. Keep the bot printing what it does. It is how you, or the assistant, find out what happened at 3 a.m.
What it costs
A bot that never stops keeps its server awake around the clock, and awake time is usage. On Server4Agent that usage comes out of your plan's credits and stops at the account's budget cap, which an assistant cannot raise. Servers with nothing running go to sleep, but a server running a bot never does, so check your usage on the dashboard after the first few days. The free plan has one small server to try it on, and Starter is $29 a month. Full limits are on the pricing page.
If all you want is the cheapest possible always-on bot and you are happy maintaining Linux, a small VPS will cost less. What you are paying for here is not having to be that person.
FAQ
Does my bot need a public URL?
Not if it uses the Gateway, which is the default for discord.js and discord.py. The bot connects out to Discord, so the project can stay private. A bot built on Discord's HTTP interactions endpoint does need a public URL, which Server4Agent provides when you publish the project.
Can one server run several bots?
Yes. A server holds several projects, and each bot runs as its own process with its own token. Bigger bots, or many of them, fit better on a medium server, which comes with Pro and above.
Does this work for Telegram and Slack bots too?
Yes. Store the token in Secrets the same way (there is a preset for Slack bot tokens, and any other key can be added by name), and describe the bot. A long-polling Telegram bot and a Slack bot in Socket Mode both run as a background process, exactly like a Discord bot.
My assistant wrote the bot in Python. Does that matter?
No. The server comes with Node.js and Python, and the assistant installs whatever else the code needs.
Can I take the bot somewhere else later?
Yes. Every project is a git repository, so you can export it and run it on any server.
Related reading
- Your AI assistant wrote the code. How do you put it online?
- Vercel or a server: where should what your AI agent builds live?
- Building a weekly metrics digest with an AI agent
- Why AI agents need persistent workspaces