Hosting Discord bots on a dedicated server

A small bot runs anywhere. A bot in thousands of communities, a music bot with dozens of voice streams, or a whole fleet of bots benefits from its own machine with predictable cores and memory.

When does a bot need a dedicated server?

When it outgrows a shared host in memory, CPU or count. Typical triggers are a bot that reached several thousand servers and caches members and messages, a music bot playing in many voice channels, a developer running ten or twenty bots for different communities, or a bot with a dashboard, database and background workers that should all live together. A dedicated machine gives each process steady performance and full control over the runtime versions.

Does a bot need open ports?

Usually not. A gateway bot opens an outbound WebSocket to Discord and receives events over it, so the firewall can drop all unsolicited inbound traffic except SSH. Two exceptions: a bot that receives slash commands through an HTTP interactions endpoint needs a public HTTPS address, and a web dashboard needs ports 80 and 443. Put both behind a reverse proxy such as nginx with a certificate.

ufw default deny incoming && ufw default allow outgoing
ufw allow 22/tcp
ufw allow 443/tcp comment "interactions endpoint and dashboard"
ufw enable

What is sharding and when do I need it?

Sharding splits the gateway connection so that each shard handles a slice of the servers your bot belongs to. Discord requires it once a bot reaches 2,500 servers, and a common target is around 1,000 servers per shard. Both discord.js and discord.py include managers that spawn shards automatically. On a single machine, run shards as separate processes so they use several cores; a 16 core server can comfortably hold dozens of shards with headroom for the database.

Bot sizeShardsTypical memory
Under 2,500 servers1200 MB to 1 GB
10,000 servers10 to 164 to 12 GB with member caching
50,000 servers50 to 6416 to 48 GB, depending on cache policy

Cache only what the bot uses. Turning off member and presence caches, and requesting only the gateway intents you need, can cut memory use several times over.

How do I host a music bot?

With a Lavalink node, a Java service that decodes and streams audio while the bot sends commands to it. Each active player costs a little CPU for encoding to Opus and some memory; one modern core handles many streams. Run Lavalink on localhost port 2333 with a strong password and give the Java process a fixed heap, for example -Xmx4G, so it cannot crowd out the bot. Audio leaves the server over the voice connection, so a busy music bot uses noticeably more bandwidth than a text bot, which unmetered ports in Europe and Canada absorb easily.

How should the processes be supervised?

With systemd or a process manager such as pm2, so a crash restarts the bot within seconds and logs land in one place. A systemd unit per bot keeps environments separate.

[Service]
User=botfleet
WorkingDirectory=/srv/bots/ticketbot
EnvironmentFile=/srv/bots/ticketbot/.env
ExecStart=/usr/bin/node --enable-source-maps dist/index.js
Restart=always
RestartSec=5

For Python bots, swap the ExecStart for the virtual environment's interpreter, such as /srv/bots/modbot/venv/bin/python -m modbot.

Where should bot data live?

In a real database on the same machine. PostgreSQL holds settings, levels, warnings and economy data with proper transactions, and Redis or Valkey works well for cooldowns, rate counters and shared caches between shards. Both run happily on NVMe drives with a few gigabytes of memory, and keeping them local means queries return in well under a millisecond.

How do I keep the token safe?

Store it in an environment file readable only by the bot user, never in the code repository. Set the file to mode 600, keep separate tokens for development and production bots, and regenerate a token at once in the developer portal if it ever appears in a log or commit. Limit SSH to keys, as our Create SSH keys guide describes, because whoever holds the server holds every token on it.

Which machine fits a bot fleet?

Small fleets need little: ESSENTIAL-1 with 6 cores and 32 GB DDR4 runs dozens of light bots plus a database for $38.40 a month on a 3, 12 or 24 month term. For large sharded bots, ESSENTIAL-4 offers 16 cores and 64 GB DDR4, and BUSINESS-2 2024 adds DDR5 and a 3 Gbps guaranteed port. Choose a data centre near Discord's busiest regions for your users; Frankfurt and Beauharnois are common picks.

Machines for Discord bot fleets

Lowest monthly price of each model across its data centres; the model page shows the price in every location.

ModelProcessorCoresMemoryDrivesPortPer month
ESSENTIAL-1Intel Xeon-E 2386G632 GB2x 512 GB SSD NVMe1 Gbps unmetered$38.40
ESSENTIAL-2Intel Xeon-E 2388G832 GB2x 512 GB SSD NVMe1 Gbps unmetered$43.20
ESSENTIAL-SAMD Ryzen 7 9700X864 GB2x 512 GB SSD NVMe1 Gbps unmetered$46.20
ESSENTIAL-4AMD EPYC 73131664 GB2x 960 GB SSD NVMe1 Gbps unmetered$106.20
BUSINESS-2 2024AMD EPYC 4344P864 GB2x 960 GB SSD NVMe3 Gbps unmetered$109.80

Start with an entry machine and move to more cores when your bot needs more shards.

See all servers and prices

Related pages

Game server hosting

Ryzen X3D and Ryzen 5000 machines for Minecraft, Rust, CS2 and FiveM worlds that need steady tick rates.

Read more

Database servers

NVMe machines with large memory for PostgreSQL, MySQL, MariaDB and MongoDB, from a single primary to replicated pairs.

Read more

Create SSH keys

Generate an Ed25519 key pair on Windows, macOS or Linux, add it to your account before ordering, and manage keys on a running server.

Read more

TeamSpeak voice server

Run your own TeamSpeak or Mumble voice server: install on Linux, the ports to open, licence slots, security settings and why a small machine is enough.

Read more

Questions and answers

Does a Discord bot need open inbound ports?

A gateway bot does not, because it connects outward over a WebSocket. Only an HTTP interactions endpoint or a web dashboard needs port 443.

When must a Discord bot use sharding?

Discord requires sharding from 2,500 servers. A common target is about 1,000 servers per shard, run as separate processes.

How much memory does a large Discord bot need?

It depends on caching. A bot in 10,000 servers commonly uses 4 to 12 GB; disabling unused member and presence caches cuts that sharply.

How do I run a Discord music bot on my server?

Run a Lavalink node on localhost with a password and a fixed Java heap, and let the bot send playback commands to it.

Where should I store a Discord bot token?

In an environment file readable only by the bot user, outside the code repository. Regenerate it at once if it is ever exposed.