> ## Documentation Index
> Fetch the complete documentation index at: https://docs.vertracloud.app/llms.txt
> Use this file to discover all available pages before exploring further.

# Discord Bot (Python) Template on Vertra Cloud: Starter with a /ping Command

> Create a Discord bot in Python on Vertra Cloud: get the token, invite the bot, run /ping and edit the code. A code template with no web address.

A minimal Discord bot in Python with discord.py 2.7.1 and a `/ping` command. This is a **code template**: the code is yours, open and editable, and Vertra Cloud runs what is in `src/`.

## What it creates

One app (code) on the Python runtime, with **no web address**: the bot only makes outgoing connections. It needs at least **100 MB** of memory (256 MB recommended) and **no image slot**, so any plan can run it. See [What are templates](https://docs.vertracloud.app/templates/overview.md).

* It logs in with the bot token, registers the `/ping` slash command on every start and answers with the gateway latency.
* It uses only the `Guilds` intent, so there is no privileged intent to turn on.
* With no token or a wrong token the process exits with code 1 and a clear message in the app log.
* Source in `src/main.py`; dependencies in `src/requirements.txt`.

## What the wizard asks

| Question | What it does |
| - | - |
| Bot token | Becomes the encrypted variable `DISCORD_TOKEN`. |

## First steps

**1. Create the bot and get the token**

In the [Discord Developer Portal](https://discord.com/developers/applications) create a **New Application**, open **Bot** and click **Reset Token**. Copy the value: it is shown only once.

**2. Paste it in the wizard**

Paste the token when the wizard asks. It is stored encrypted and never goes in the code.

**3. Invite the bot**

In **OAuth2 > URL Generator** tick the scopes `bot` and `applications.commands`, open the generated URL and choose your server.

**4. Check**

After the deploy the app log shows `Logged in as <bot name>`. In Discord, type `/ping`: the bot answers `Pong!` with the latency. The global command can take a few minutes to appear the first time.

## Make it your own

Open `src/main.py`, add your commands and deploy again, or restart if you edited in the app's editor. To add libraries, list them in `requirements.txt` with a pinned version: the platform installs dependencies on every deploy.

Editing the code detaches the app from the template, so it stops receiving new versions of it. See [Update and roll back](https://docs.vertracloud.app/templates/use/updates-and-rollback.md#detached-apps-and-removed-templates).

## Reference

| Item | Value |
| - | - |
| Variable | `DISCORD_TOKEN` (encrypted, from the wizard) |
| Start command | `python3 -u main.py` |
| Main file | `main.py` |
| Memory | 100 MB (minimum), 256 MB (recommended) |
| Web | None |
| Zero-downtime deploy | Off (one token is one copy) |

## Limits and common problems

* Two copies with the same token would answer twice, so zero-downtime deploy is off.
* The minimum is 100 MB, and 256 MB (the recommended size) is enough for a simple bot. A bot on many servers or with a large cache needs more; you can raise the memory.
* Discord global commands are slow to propagate. For tests, register guild commands in your code.
* **`Login failed` in the log.** `DISCORD_TOKEN` is not the bot token. Reset it in the Portal, update the variable and restart.
* **`/ping` does not show up.** Wait a few minutes and check that the invite had the `applications.commands` scope.
* **The app does not stay up.** Without a valid token the process exits with code 1. Fix the token and restart.

## License

The template's code is by Vertra Cloud, under the MIT license. discord.py is distributed under the [MIT license](https://github.com/Rapptz/discord.py/blob/master/LICENSE).

See also the [other official templates](https://docs.vertracloud.app/templates/catalog.md) and the tutorial [Create a Discord bot template](https://docs.vertracloud.app/templates/tutorials/discord-bot-code.md).


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.