A VPS for a Discord bot: gateway or interactions, shards, intents and voice
A Discord bot is either a long-running program that keeps a WebSocket connection to Discord open, or a small web service that Discord calls over HTTPS. Either way it needs a machine that stays online around the clock. The usual libraries are discord.py in Python, discord.js in Node.js and JDA in Java. All three handle reconnects, rate limits and sharding for you; what the server needs depends mostly on how the bot receives events.
Gateway connection or interactions endpoint
- Gateway. The bot opens an outgoing WebSocket to Discord and receives messages, member joins, reactions and slash commands over it. No domain, certificate or open port is needed, because the server only connects outward. This is the default mode in discord.py, discord.js and JDA.
- HTTP interactions endpoint. A bot that only answers slash commands, buttons and modals can instead give Discord a public HTTPS URL in the Developer Portal. Discord sends each interaction as a POST request. The server must verify the Ed25519 signature from the
X-Signature-Ed25519andX-Signature-Timestampheaders, answer the PING check and reply within 3 seconds, or defer the reply and follow up later. This requires a domain, a web server such as Nginx on port 443 and a valid TLS certificate, for example a free one from Let's Encrypt.
An interactions-only bot scales like an ordinary web app; a gateway bot needs a process that never stops, but no inbound ports.
Memory, shards and intents
A small gateway bot on a handful of servers uses roughly 50–150 MB of RAM; JDA starts higher because of the JVM, so plan for 256–512 MB of heap. The real driver is the cache: every guild, channel, member and message the library keeps in memory adds up. On 1 GB you can run one or two bots with SQLite; with PostgreSQL, Redis or Docker take 2 GB. Trimming the member and message cache often saves more than a bigger plan.
Once a bot reaches 2,500 guilds, Discord requires sharding: one gateway connection, or shard, may serve at most 2,500 guilds, and the GET /gateway/bot endpoint returns the recommended shard count, roughly one per 1,000 guilds. Each shard has its own connection and cache, so budget memory per shard rather than per bot. Large bots split shards across processes or servers; shard logins are rate limited, so a full restart takes a while.
Request only the intents you use. Three are privileged: server members, presence and message content. A bot in fewer than 100 servers can switch them on in the Developer Portal; after that it has to be verified, and Discord approves each privileged intent only with a stated reason.
Uptime, tokens and rate limits
Run the bot as a service that restarts by itself: a systemd unit with Restart=always, PM2 with pm2 startup so it comes back after a reboot, or a container with restart: unless-stopped. The libraries resume the gateway session after short network drops; your job is to bring the process back if it crashes. Environment details are on the VPS for Python, VPS for Node.js and VPS for Docker pages.
The bot token works like a password to the bot account. Keep it in an environment variable or a secrets file outside the repository and reset it in the Developer Portal at the first sign of a leak. Log in to the server with an SSH key and turn off password login.
Discord limits API requests per route and globally, and answers with HTTP 429 and a retry_after value when a limit is hit. The libraries queue requests and wait on their own; trouble starts with custom HTTP code that retries in a tight loop. Too many failed requests (401, 403 and 429) in a short period get the server's IP address temporarily banned from the API.
Logs, voice and server location
Log errors, reconnects and command usage, but not message contents or tokens, and set up log rotation on day one so the disk does not fill up. Voice bots are a different kind of load: audio travels over UDP to Discord's voice servers, Opus encoding costs CPU for every active stream, and each stream is a constant flow of traffic. A music bot needs dedicated cores and should play only audio you have the rights to.
For a text bot, location matters little: the gateway and API sit behind a global edge network, and a few tens of milliseconds go unnoticed. Much of Discord's core infrastructure is in the United States, so a server on the US East Coast gives the shortest API round trip. For voice, latency to the voice server matters more. It is set by the channel's region or picked near the users, so place the bot close to the community it serves. To compare locations, hourly billing lets you pay only for the hours a server runs.
What the Developer Terms allow
Run only a bot account created in the Developer Portal: self-bots that automate a user account are forbidden and get the account banned. Do not send unsolicited or mass DMs, do not spam channels, and do not collect user data beyond what the bot needs to work. Scraping members or messages for other purposes breaks the Developer Terms and the Developer Policy.