Optimizing Discord Bot Memory Usage and Handling Privileged Intents

Published on | Updated

Reduce Discord bot memory usage by managing caches, sweeping unused data and enabling only the privileged intents you need, now that review starts at 10,000 users. Code examples for discord.js and discord.py.

Rows of server racks with glowing purple cables in a data center

As your Discord bot scales from one server to hundreds, memory usage grows significantly. A bot that uses 50 MB on a single server might consume 500 MB or more when added to 200+ servers, especially if it caches guild members through Privileged Intents.

This guide explains why memory grows, how to control it through cache management and intent configuration, and why reliable RAM allocation matters for production bots.

Why Discord bots consume more memory than expected

Discord bot libraries like discord.js and discord.py cache data locally to avoid making API calls for every piece of information. By default, they cache:

  • Guilds (servers): Basic info, roles, channels, emojis
  • Members: User objects for every member in every server
  • Messages: Recent messages in every channel the bot can see
  • Presences: Online/offline status and activities for all members
  • Voice states: Who is in which voice channel

For a bot in 100 servers with an average of 500 members each, caching all members means storing 50,000 user objects in memory. With presences enabled, each object is larger because it includes activity data.

The Privileged Intents problem

Discord introduced Privileged Intents to control which data bots can access. Since 10 June 2026, a bot can switch them on in the Developer Portal until more than 10,000 unique users can see it across all its servers. From that point Discord asks for a review, with 90 days to apply and a yearly reapplication once access is granted. The old rule of applying at 100 servers is gone, although App Verification is still required to grow past 100 servers. Our privileged intents guide covers the details.

The two most memory-intensive intents are:

GuildMembers Intent

  • Enables receiving GUILD_MEMBER_ADD, GUILD_MEMBER_UPDATE, GUILD_MEMBER_REMOVE events
  • Populates the member cache for all servers
  • Required for: member welcome messages, role tracking, moderation logging

GuildPresences Intent

  • Enables receiving presence update events (online/offline/playing)
  • Stores activity data for every member in every server
  • Required for: status-based features, rich presence tracking

Message Content Intent

  • Required to read the content of server messages, except messages that mention your bot and your bot's own messages. DMs with the bot arrive with their content either way
  • Little extra memory on its own, but like the other two it needs Discord's review once more than 10,000 users can see your bot

Step 1: Only enable intents you need

// discord.js: only enable what you actually use
const { Client, GatewayIntentBits } = require('discord.js');

const client = new Client({
  intents: [
    GatewayIntentBits.Guilds,           // Always needed
    GatewayIntentBits.GuildMessages,     // For message events
    // GatewayIntentBits.GuildMembers,   // Only if you need member events
    // GatewayIntentBits.GuildPresences, // Only if you track presence
    // GatewayIntentBits.MessageContent, // Only if you read message content
  ]
});
# discord.py: selective intents
import discord

intents = discord.Intents.default()
intents.message_content = True  # Only if needed
# intents.members = False       # Keep disabled if not needed
# intents.presences = False     # Keep disabled if not needed

client = discord.Client(intents=intents)

Rule of thumb: If you are not using an intent's data, do not enable it. Each enabled intent increases memory usage proportionally to your server count.

Step 2: Configure cache sweeping (discord.js)

discord.js allows you to automatically clean up cached data that is no longer needed:

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

const client = new Client({
  intents: [
    GatewayIntentBits.Guilds,
    GatewayIntentBits.GuildMessages,
  ],
  sweepers: {
    ...Options.DefaultSweeperSettings,
    // Every 10 minutes, drop cached messages older than 30 minutes
    messages: {
      interval: 600,   // 10 minutes in seconds
      lifetime: 1800,  // 30 minutes in seconds
    },
    // Every hour, drop cached users that are not bots (never the client itself)
    users: {
      interval: 3600,
      filter: () => (user) => !user.bot && user.id !== user.client.user.id,
    },
    // Every hour, drop cached guild members that are not bots
    guildMembers: {
      interval: 3600,
      filter: () => (member) => !member.user.bot,
    },
  },
  makeCache: Options.cacheWithLimits({
    ...Options.DefaultMakeCacheSettings,
    MessageManager: 50,  // keep at most 50 messages per channel
    GuildMemberManager: {
      maxSize: 200,      // keep at most 200 members per guild
      keepOverLimit: (member) => member.id === member.client.user.id, // always keep the bot's own member
    },
    PresenceManager: 0,  // don't cache presences at all
  }),
});

Options comes from discord.js itself. The keepOverLimit line follows the discord.js guide's cache customization example, which warns that the bot's own member must stay in the cache "so that the client can function correctly in guilds". The same guide calls cache customization an advanced topic where "it is very easy to introduce errors", and says customizing the guild, channel, guild channel, role and permission overwrite managers is unsupported.

Step 3: Monitor memory usage

Add memory monitoring to catch leaks early:

// Log memory usage every 5 minutes
setInterval(() => {
  const used = process.memoryUsage();
  console.log(JSON.stringify({
    timestamp: new Date().toISOString(),
    rss: `${Math.round(used.rss / 1024 / 1024)} MB`,
    heap_used: `${Math.round(used.heapUsed / 1024 / 1024)} MB`,
    heap_total: `${Math.round(used.heapTotal / 1024 / 1024)} MB`,
    guilds: client.guilds.cache.size,
    users: client.users.cache.size,
  }));
}, 300000);
# discord.py memory monitoring
import os

import psutil
from discord.ext import tasks

@tasks.loop(minutes=5)
async def memory_monitor():
    process = psutil.Process(os.getpid())
    mem = process.memory_info()
    print(f"RSS: {mem.rss / 1024 / 1024:.1f} MB | "
          f"Guilds: {len(client.guilds)} | "
          f"Users cached: {len(client.users)}")

Step 4: Implement lazy loading

Instead of caching everything upfront, fetch data only when needed:

// Cache only: fast, but the member can be missing once caches are limited
const member = guild.members.cache.get(userId);

// Cache first, then the API: fetch() returns a cached member if there is one
const member = await guild.members.fetch(userId);

// Always ask Discord, when you need fresh data
const member = await guild.members.fetch({ user: userId, force: true });

These are three alternatives, so pick one per lookup. With limited caches, the second one is the usual choice: discord.js only calls the API when the member is not cached, unless you pass force: true.

Memory usage by scale

The ranges below are rough estimates for discord.js bots, not measurements. Real numbers depend on member counts, the intents you request and what your bot keeps in memory, so measure your own bot with the monitoring code above before you pick a plan.

ScaleWithout OptimizationWith Optimization
1-10 servers40-80 MB30-50 MB
50-100 servers150-300 MB80-150 MB
200-500 servers400-800 MB150-300 MB
1000+ servers1-3 GB300-600 MB

How much sweeping and cache limits save depends on how much of the default cache your bot actually uses.

Why RAM allocation matters

When your bot exceeds its allocated RAM, the hosting environment kills the process (OOM, Out of Memory). This causes:

  • Immediate disconnection from Discord
  • Lost in-flight interactions (users see "interaction failed")
  • Potential data corruption if writing to a database
  • Restart delay while the process is recreated

Reliable RAM allocation on enterprise hardware ensures your bot has consistent, fast memory access. Space-Node's DDR5 memory on Ryzen 9 nodes handles memory-intensive operations (like cache sweeps and garbage collection) faster than older DDR4 platforms.

Choosing the right hosting plan

Based on the optimization strategies above:

  • Small and medium bots (1 to 100 servers): Space-Node Growth plan (512 MB), which covers the first two rows of the table above, with cache sweeping enabled as the bot grows
  • Large bots (100+ servers): Space-Node Pro plan (1 GB) or XL plan (2 GB), or VPS hosting for full control

Our free Starter plan (64 MB) is not available right now, so Growth is the smallest plan you can order: €0.50 a month, billed €3.00 every 6 months plus a one-time €0.50 setup fee on the 6 month and 1 year terms. Pro is €1.00 a month for 1 GB RAM, billed €6.00 every 6 months plus the same setup fee, and XL is €2.00 a month for 2 GB, billed €12.00 every 6 months plus the same setup fee. Our Standard VPS plans start at €4.99 a month for 4GB RAM and Premium VPS plans at €4.20 a month for 2GB.

View Discord Bot Hosting Plans

The short version

Memory optimization is not optional for scaling bots. By selectively enabling intents, implementing cache sweeping, and monitoring usage, you can keep memory consumption under control. Combined with reliable hosting that provides consistent DDR5 RAM and auto-restart protection, your bot stays online and responsive as it grows.