Host a Discord bot 24/7 with your AI, over MCP (2026)
Does your bot work on your computer? Connected to while over MCP, your AI keeps it running 24/7, and the bot restarts on its own if it stops.
By Aloïs Oddon, co-founder of Nextmap. Facts checked on November 19, 2026.
The short version. Over MCP, your AI deploys your Discord bot with while: it runs 24/7, with no server to manage, and its token stays secret. What matters, like deleting a database, waits for a person’s approval.
Prerequisites
- A Discord bot, in Node.js or Python.
- An AI that works in a terminal: Claude Code, Codex, Cursor or Gemini CLI.
Step 1: Give your AI this message
Open your AI in your bot’s folder, and paste this message into it:
Connect to while with my account (while.sh/agents), then put my app on while.
Your AI adds while’s MCP server itself. If it asks you to, restart it. On the first call to while, a page opens in your browser. In Claude Code, if it doesn’t open, type /mcp, choose while, then Authenticate. On that page, choose “A new app”, then click Authorize.
Step 2: Check that your bot is connected
Your AI reads the bot’s logs in while, and tells you when it’s connected to Discord.
What your AI does
It writes while.yaml next to your bot:
apiVersion: while/v1
project: mon-bot
services:
- name: bot
type: worker
command: [node, bot.js]
network:
egress: all
Your bot runs continuously, with no public address. The last two lines open the internet to it, so it can reach Discord.

Keep the bot’s token secret
You, to your AI: Connect the bot with its Discord token.
You enter the token in while: your bot receives it, and your AI never sees it.
Add a command to the bot
You, to your AI: Add the /planning command to the bot.
Your AI changes the code and deploys the bot again in a few seconds, without ever running it twice.
Post at a set time
You, to your AI: Post the schedule every Monday at 9 am.
Your AI declares a scheduled job, with the same code and the same token.
Add a database
You, to your AI: Add a PostgreSQL database.
Your AI declares the database in while.yaml, and its address reaches your code in DATABASE_URL. The database is backed up every day, with a way back to a precise moment over 14 days.
Go back to the previous version
You, to your AI: Go back to the previous version of the bot.
The previous version of the bot takes over in a few seconds, without ever running twice. Then your AI reads what broke in while’s logs, fixes it and deploys again.
In the docs: PostgreSQL databases, Scheduled jobs, Worker, Versions and rollback and Variables and secrets.
Next steps
Sources
- Discord, messages (posting a message to a channel through the HTTP API), accessed November 2, 2026
- Discord, getting started (the bot token), accessed November 2, 2026