A Discord bot keeps a persistent WebSocket connection open to Discord's Gateway, so it needs a process that runs 24 hours a day. How much memory that process uses depends on four things: the runtime (Node.js, Python or Java), what the library keeps in its cache, how many servers and members the bot sees, and whether it plays audio.
This guide gives a starting point for each type of bot, explains where the memory goes and shows how to measure your own bot before choosing a plan.
Starting points by bot type
| Bot | Starting point | Astrol Nodes plan |
|---|---|---|
| Moderation, utility or ticket bot in a few servers (discord.js or discord.py) | 256 MB | Bronze Bot, €0.50/month |
| Bot with the members intent in large servers, or with its own database and web dashboard | 512 MB | Silver Bot, €0.99/month |
| Music bot (JMusicBot, or your bot together with a Lavalink server) | 1 GB | Gold Bot, €1.49/month |
| Several bots in one plan, many simultaneous music players, or a bot close to 2,500 servers | 4 GB | Diamond Bot, €4.99/month |
These are starting points, not limits. The section on measuring explains how to check the real figure once the bot is online and when it is time to move up.
Where the memory goes
- The runtime. Node.js, Python and the Java virtual machine each use a fixed amount of memory before your code does anything. Java has the largest base, which is why Java bots and Lavalink need larger plans.
- The library cache. discord.js and discord.py keep servers, channels, roles, members and recent messages in memory so they do not have to ask Discord for them again. discord.py keeps the last 1,000 messages by default (
max_messages). discord.js limits its message caches by default and lets you limit others. - Privileged intents. With the
GUILD_MEMBERSintent the bot receives the member list of every server, and in servers with thousands of members this becomes the largest part of the cache. In discord.py,chunk_guilds_at_startupis enabled by default when the members intent is on, so the whole member list is requested at startup. - Audio. A music bot downloads, decodes and sends audio continuously. Lavalink, the audio server many music bots use, runs as a separate Java process with its own memory.
- Your own code. A database, a web dashboard or image generation for welcome cards add their own memory on top of the bot.
discord.js bots
The discord.js guide describes cache customisation as the way "to reduce memory usage". A bot that does not need reactions or old messages can limit those caches and sweep messages periodically:
const { Client, GatewayIntentBits, Options } = require('discord.js');
const client = new Client({
intents: [GatewayIntentBits.Guilds, GatewayIntentBits.GuildMessages],
makeCache: Options.cacheWithLimits({
...Options.DefaultMakeCacheSettings,
ReactionManager: 0,
}),
sweepers: {
...Options.DefaultSweeperSettings,
messages: { interval: 3_600, lifetime: 1_800 },
},
});
The guide also warns that customising the caches of servers, channels, roles and permission overwrites is unsupported and breaks functionality, so limits should only be applied to the managers it documents.
discord.py bots
In discord.py the same savings come from three Client parameters: a smaller message cache, the member cache and the start-up chunking.
import discord
intents = discord.Intents.default()
client = discord.Client(
intents=intents,
max_messages=200, # default 1000; None disables the message cache
member_cache_flags=discord.MemberCacheFlags.none(),
chunk_guilds_at_startup=False,
)
Turning the member cache off means that member information has to be fetched from Discord when a command needs it, so this setting suits bots that rarely read member lists.
Java bots and JMusicBot
Bots written with JDA, and JMusicBot in particular, run on the Java virtual machine. The JVM reserves its heap at start-up and also uses memory outside the heap, so the heap should not take the whole plan. In a 1 GB plan, a start command such as java -Xmx768m -jar JMusicBot.jar leaves a quarter of the memory for the rest of the process.
Music bots with Lavalink
Lavalink is a separate audio server, written in Java and requiring Java 17 or later, to which your bot connects. When the bot and Lavalink run in the same plan, the two processes share its memory, so 1 GB is the reasonable starting point. A bot that plays music in many servers at the same time needs more, and the 4 GB plan or a separate Lavalink plan keeps the audio from competing with the bot for memory.
When a bot needs sharding
Discord's documentation sets a limit of 2,500 servers per Gateway connection: "apps that are in 2500+ guilds must enable sharding". The discord.js guide recommends starting to prepare at around 2,000 servers.
Sharding affects memory because each shard is a separate connection. The discord.js ShardingManager runs shards as separate processes or threads, and each process has its own runtime base. The guide notes that internal sharding, with every connection in one process, "is not ideal for bigger bots due to high memory usage". A bot approaching this size should plan for 4 GB.
Two other limits arrive earlier. Bots in 100 or more servers have to be verified by Discord, and verified bots need approval to use the privileged intents (GUILD_MEMBERS, GUILD_PRESENCES and MESSAGE_CONTENT).
How to measure your bot's memory
- In the panel. The console view of each server shows CPU and RAM usage in real time. Watching it for a day, including restarts, shows the real peak.
- In Node.js.
process.memoryUsage().rssreturns the memory the process is using, in bytes. - In Python. On Linux,
resource.getrusage(resource.RUSAGE_SELF).ru_maxrssreturns the peak memory of the process in kilobytes, with no extra package.
As a rule, if usage stays above three quarters of the plan, the next plan avoids restarts caused by running out of memory. Start-up deserves particular attention: a bot that requests member lists when it connects reaches its peak in the first minutes.
Discord bot plans at Astrol Nodes
| Plan | RAM | CPU | Storage | Databases | Backups | Price |
|---|---|---|---|---|---|---|
| Bronze Bot | 256 MB | 50% | Unlimited NVMe | 1 | - | €0.50/month |
| Silver Bot | 512 MB | 100% | Unlimited NVMe | 1 | 1 | €0.99/month |
| Gold Bot | 1 GB | 200% | Unlimited NVMe | 2 | 2 | €1.49/month |
| Diamond Bot | 4 GB | 300% | Unlimited NVMe | 3 | 5 | €4.99/month |
Every plan runs 24/7 with automatic restart if the process stops, includes a web console, file manager and SFTP access, and supports bots written in Node.js, Python or Java, with ready-made templates for JMusicBot, Lavalink, Red-DiscordBot and Aoede among others. Bots can be hosted in Frankfurt (Germany) or Miami (USA), and the server is ready less than a minute after payment. A bot can move to a larger plan at any time without losing its files.
See the Discord bot hosting plans or the step-by-step guide to hosting your bot.
Sources
- Discord Developer Documentation, Gateway: connections, sharding and privileged intents.
- discord.js Guide, Cache customization and Sharding.
- discord.py documentation, Client parameters.
- Lavalink documentation, Running the binary.