How much RAM does a Discord bot need?

A small Discord bot in a few servers and without music usually runs on 256 to 512 MB of RAM. Usage grows with servers, cached members, shards and heavy libraries.

Updated 5 min read

Learning objectives

After reading this article you will be able to:

  • Estimate a bot's RAM from its size and the features it uses
  • Measure your process's real memory use and spot leaks
  • Trim the discord.js and discord.py caches to use less
On this page

The RAM question comes early: you are about to pick a hosting plan and need a number. There is no single one. A bot that answers slash commands in ten servers and a moderation bot in thousands of servers with a member cache use very different amounts of memory.

Still, you can estimate it and, better yet, measure it. Below you see what takes memory in a bot, how to read your process's real usage and how to cut what you do not need.

RuntimeLibrary cacheExtra librariesSpikes (temporary)Simple slashfew serversModerationhundreds of serversImages or AIcanvas, sharpRAM
The runtime is the fixed floor; what makes RAM grow is the library cache, heavy libraries and command spikes.

What takes up RAM in a Discord bot?#

A bot's memory splits into four parts:

  1. Runtime: Node.js or Python loaded, plus your code and dependencies. This is the floor, and it exists even with zero servers.
  2. Library cache: guilds, channels, roles, emojis, members and messages that the Gateway sends and the library keeps. This is the part that grows most with the size of the bot.
  3. Extra libraries: image processing, in-memory databases, API clients, audio. A single heavy dependency can double usage.
  4. Spikes: a command that downloads a large file, renders an image or loads a whole table uses memory for a few seconds.

How much RAM does each kind of bot usually use?#

As a starting point, not a rule:

Bot type Starting range
Simple slash commands, few servers 256 to 512 MB
Moderation or economy, hundreds of servers 512 MB to 1 GB
Images (canvas, sharp) or AI 1 GB or more, depending on load
Many servers, with sharding grows per shard, measure
Music heavy audio usually lives in a separate server (Lavalink), see what is Lavalink

These ranges are practical sizing references, not official limits of any library. Real usage depends on your code, so the next section shows how to measure it.

How do you measure your bot's RAM?#

Measure RSS (the physical memory the process actually occupies), not only the heap. In Node.js, log it every minute:

js
setInterval(() => {
  const { rss, heapUsed } = process.memoryUsage();
  console.log(`rss=${(rss / 1048576).toFixed(0)}MB heap=${(heapUsed / 1048576).toFixed(0)}MB`);
}, 60_000);

In Python (Linux), with no extra dependencies:

python
def usage_mb() -> float:
    # VmRSS is current RSS, in kB (Linux)
    with open("/proc/self/status") as f:
        kb = next(int(l.split()[1]) for l in f if l.startswith("VmRSS:"))
    return kb / 1024

Leave the bot running for a few hours with normal traffic and look at the curve. A line that rises and levels off is the cache filling up, and that is fine. A line that keeps climbing is a leak.

How do you trim the cache in discord.js?#

In discord.js v14, Options.cacheWithLimits sets how much each cache (messages, members, reactions) keeps. By default, discord.js limits messages to 200 per channel (Options.DefaultMakeCacheSettings). If your bot does not read old messages, cut further:

js
const { Client, GatewayIntentBits, Options } = require('discord.js');

const client = new Client({
  intents: [GatewayIntentBits.Guilds],
  makeCache: Options.cacheWithLimits({
    ...Options.DefaultMakeCacheSettings,
    MessageManager: 0,
    ReactionManager: 0,
    GuildMemberManager: {
      maxSize: 50,
      keepOverLimit: (member) => member.id === client.user.id,
    },
  }),
});

client.login(process.env.DISCORD_TOKEN);

Even more important: request only the intents you need. Without GuildMembers and GuildMessages, the Gateway stops sending member and message events, and far less is left to cache. See the article on privileged intents.

How do you trim the cache in discord.py?#

In discord.py 2.x, the max_messages parameter sets the message cache size (the default is 1000) and member_cache_flags controls which members are kept:

python
import os
import discord

intents = discord.Intents.default()  # no members, no message_content

client = discord.Client(
    intents=intents,
    max_messages=100,
    member_cache_flags=discord.MemberCacheFlags.none(),
)

client.run(os.environ["DISCORD_TOKEN"])

Passing max_messages=None turns the message cache off entirely. If you enable the members intent, the library loads the members of every server at startup (chunk_guilds_at_startup defaults to True in that case), which the documentation describes as very slow with many servers.

What to do when RAM only goes up?#

Work through this order:

  1. Confirm it is the cache: lower the limits and see whether the curve flattens.
  2. Look for duplicate listeners: calling client.on(...) inside a command handler adds a new listener on every use. Node.js warns with MaxListenersExceededWarning.
  3. Look for collections that only grow: a global Map or list (cooldowns, queues, sessions) that never removes entries.
  4. Move heavy work out of the process: large images and queries without LIMIT are avoidable spikes.
  5. Tune the heap, if needed: in Node.js, --max-old-space-size (in MiB) sets the V8 heap ceiling. The documentation suggests, on a 2 GiB machine, something like 1536 to leave headroom for the system. It keeps the heap under a ceiling but does not fix a leak.

A bot that crashes for lack of memory and restarts on its own usually has one of the issues above. If that sounds like your bot, also read why a bot goes offline.

When do you need shards?#

Discord requires sharding once the bot reaches 2,500 servers, and each shard holds at most 2,500. Before that, one process is enough. After that, each shard has its own cache, so total RAM grows with the number of shards. Trimming the cache is what keeps the cost in check. For the money side, see how much it costs to host a bot and how to size RAM and CPU.

How to do this on Square Cloud#

The number you measured becomes the memory you reserve for the bot. On Square Cloud, the plan's RAM is a pool shared by all your applications. The minimum is 256 MB per background application, such as a bot, and one application can use up to 32 GB. You set each application's RAM in its settings or through the API and change it whenever you want. There is no autoscaling: the adjustment is yours.

Hobby starts at R$12.49 per month with 1 GB of RAM, which fits several small bots in the same pool. Containers are always on. If the bot goes past its RAM limit, the application stops and does not come back on its own, not even with automatic restart: raise the memory and start it again. CPU and RAM metrics appear in the dashboard, with 24 hours of history, which helps you check the curve described above. The squarecloud.app file is optional: the dashboard generates it on deploy, with the memory you choose, or you can write it at the project root.

See Discord bot hosting on Square Cloud and the plans.

Bot hosting

Keep your bot online 24/7 with automatic restarts

Learn more

FAQs

Is 256 MB of RAM enough for a Discord bot?

For a simple bot with slash commands and few servers, usually yes. Bots with many servers, large member caches, images or audio need more. Measure your process before you decide.

Why does my bot use more and more RAM over time?

Most often it is an unbounded cache (messages, members) or a leak in your code, such as listeners added on every command or lists that only grow. Limit the cache and watch usage over several hours.

At how many servers do I need shards?

Discord requires sharding from 2,500 servers, and each shard supports at most 2,500. Every extra shard keeps its own cache, so total RAM goes up.

Does Node.js or Python use less RAM for a bot?

It depends on what the bot does. Both run small bots in a few hundred MB. Cache settings and extra libraries, such as image processing, weigh more than the language.

Next articleDiscord 429 Too Many Requests: rate limits and Cloudflare bans explainedA Discord 429 error means your bot hit a rate limit. Learn the three kinds of limits, how to read the headers, how to fix it and avoid a temporary IP ban.