---
title: "Host a Discord bot 24/7 in 2026: no server, token kept safe"
url: https://while.sh/en/guides/host-discord-bot/
author: "Aloïs Oddon, co-founder of Nextmap"
updated: 2026-11-19
---

# 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.

> **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:

```text titre="The message to give your AI"
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:

```yaml titre="while.yaml"
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.


<figure class="illus"><img src="/illustrations/discord-veille-1200.webp" srcset="/illustrations/discord-veille-768.webp 768w, /illustrations/discord-veille-1200.webp 1200w" sizes="(min-width: 48rem) 46rem, 100vw" width="1536" height="1024" loading="lazy" decoding="async" alt="Host a Discord bot 24/7 with no sleep: an always-on Discord bot answering day and night, its token kept out of the AI's reach, on while in France" /><figcaption>Your bot runs day and night, and its token stays in while.</figcaption></figure>

## 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.

## Next steps

- [Run a scheduled job](/en/guides/run-cron-job/)
- [Deploy a Docker container](/en/guides/deploy-docker-container/)
- [Compare the hosts that have an MCP server](/en/comparisons/mcp-hosting-claude-code/)

## Sources

1. [Discord, messages (posting a message to a channel through the HTTP API)](https://docs.discord.com/developers/resources/message), 2026-11-02
2. [Discord, getting started (the bot token)](https://docs.discord.com/developers/quick-start/getting-started), 2026-11-02

## Questions

### Does my bot answer twice during an update?

No: a new version replaces the old one without ever running twice.

### Node.js or Python?

Both, or any other language with a Dockerfile.

### How much does a bot cost?

A bot uses little, and you only pay for the CPU and memory it uses.

### Where do my app and its data run?

In France, at Nextmap. The database is backed up every day, with a way back over 14 days, once a person approves.

### Does my AI see my credentials?

No. You paste them into while, the app uses them, and your AI never sees them. Every call is logged.
