guides

The discord.js gotchas that cost me a week each

Eight discord.js production failures I learned the hard way running 500+ deployed bots — 50013 permission walls, 3-second interaction races, silent intent killers, partial messages, and more. With the code patterns that fix each one.

👤
Alex Chen
Discord Community Expert
May 20, 2026
10 min read
Code on a screen at night — the kind of thing you debug at 3am.

About this list

I run a service that auto-generates and deploys Discord bots from natural-language descriptions. Over 500 bots are running on it. Most of what I learned came from logs at 3am after someone's bot stopped responding, or a community went silent because of an undocumented Discord behavior.

Here's the list I wish I'd had on day one. Each section is a real failure I've debugged more than once.

1. "Missing Permissions" (50013) is usually about role position, not permissions

The first time I hit this I spent two hours auditing the bot's permission integer. It was correct. The bot still couldn't kick anyone.

The thing nobody puts in big letters: discord.js permissions are gated by role hierarchy. A bot can have the KickMembers permission and still fail to kick anyone whose top role sits at or above the bot's top role.

client.on('interactionCreate', async (interaction) => {
  if (!interaction.isChatInputCommand()) return;
  if (interaction.commandName !== 'kick') return;

  const target = interaction.options.getMember('user');
  const botMember = interaction.guild.members.me;

  if (target.roles.highest.position >= botMember.roles.highest.position) {
    return interaction.reply({
      content: "I can't kick that user — their role is at or above mine.",
      ephemeral: true,
    });
  }

  await target.kick(interaction.options.getString('reason') ?? 'No reason');
  await interaction.reply(`Kicked ${target.user.tag}.`);
});

Fix in Discord: drag the bot's role above the roles it needs to manage in Server Settings, Roles. This is the single most common reason a "working" bot doesn't work.

2. "Unknown Interaction" (10062) is a 3-second race

Slash commands give you exactly 3 seconds to respond. If you call any awaited DB query, third-party API, or LLM before .reply(), you lose that race.

Wrong:

const result = await callLLM(prompt);   // 2.4s
await interaction.reply(result);        // 10062

Right:

await interaction.deferReply();         // buys you 15 minutes
const result = await callLLM(prompt);
await interaction.editReply(result);

The deferred reply pattern is one of those things you need to internalize once and then never get bit by again.

3. Intent flags are silent killers

This one is brutal because there's no error. Your bot connects, shows as online, registers commands, and never reads a message.

Two parts:

  1. In the Discord Developer Portal, toggle "Message Content Intent" on.
  2. In your client config, list it:
import { Client, GatewayIntentBits } from 'discord.js';

const client = new Client({
  intents: [
    GatewayIntentBits.Guilds,
    GatewayIntentBits.GuildMessages,
    GatewayIntentBits.MessageContent, // without this, message.content is empty
    GatewayIntentBits.GuildMembers,
  ],
});

If you skip either step, message.content arrives as an empty string and your prefix commands look broken for no apparent reason.

4. Reactions and edits on old messages are partial

If someone reacts to a message your bot didn't observe being created (anything older than the bot's current session), the event payload is partial. Touching .content returns null until you fetch.

client.on('messageReactionAdd', async (reaction, user) => {
  if (reaction.partial) {
    try { await reaction.fetch(); } catch { return; }
  }
  if (reaction.message.partial) {
    try { await reaction.message.fetch(); } catch { return; }
  }
  // safe to use reaction.message.content now
});

Add the Partials config too:

import { Client, Partials } from 'discord.js';

new Client({
  intents: [/* ... */],
  partials: [Partials.Message, Partials.Channel, Partials.Reaction],
});

Build your own Discord bot in minutes — no coding needed.

VibeBot lets you describe what you want and deploys it to the cloud instantly.

Start Building Free

5. Ephemeral replies don't behave like normal messages

You can't fetch them with channel.messages.fetch(). You can't add reactions to them. If you want to update one later, you need the original interaction token, not a message ID:

await interaction.reply({ content: 'Loading…', ephemeral: true });
// later
await interaction.editReply({ content: 'Done.' });

If you serialize the interaction across processes (a queue, a webhook handler, etc.), serialize the token, not the message reference.

6. Process crashes leave gateway sessions hanging

If your bot crashes hard without closing the websocket, Discord keeps that session alive on their end for a few minutes. New deploys then count against the 1000/day session start limit, and on cold restarts you can see a window where two instances of your bot post duplicate messages.

async function shutdown(signal) {
  console.log(`[bot] ${signal} received, closing gateway`);
  try { await client.destroy(); } catch {}
  process.exit(0);
}
process.on('SIGTERM', () => shutdown('SIGTERM'));
process.on('SIGINT',  () => shutdown('SIGINT'));

process.on('unhandledRejection', (err) => {
  console.error('[bot] unhandled rejection:', err);
  // log and continue
});
process.on('uncaughtException', (err) => {
  console.error('[bot] uncaught:', err);
  shutdown('uncaughtException');
});

If you're running on a container platform that sends SIGTERM before forcibly killing, this single block saves you a class of bugs you'd never spot from a single bot.

7. Rate limits aren't always 429s

The REST client emits a rateLimited event for the soft cases (Discord's per-route bucket warnings). If you log it from day one, you get a free monitoring signal:

client.rest.on('rateLimited', (info) => {
  console.warn('[ratelimit]', {
    route: info.route,
    method: info.method,
    timeToReset: info.timeToReset,
    limit: info.limit,
  });
});

In production these almost always trace back to one bot in a 10k-member server doing something dumb in a loop. They never show up in your error monitoring otherwise.

8. Most production failures aren't bugs in your code

When you run a few hundred bots, the failure distribution shifts. Probably 30% of "the bot is broken" tickets I've seen trace back to:

  • Server admin moved roles around
  • User revoked the bot's invite
  • The bot got rate-limited because someone scripted 1000 reactions
  • Discord shipped a behavior change
  • A channel was deleted that the bot was scheduled to post in

Your bot needs to log enough that you can prove which of these happened, fast. A single structured log per important event (action attempted, guild ID, user ID, outcome, latency) gets you 80% of the way there.

Where this came from

I learned most of this the hard way running VibeBot, where users describe a Discord bot in plain English and the system generates and deploys discord.js code for them. The interesting failure mode in that setup is that the LLM-generated code has to handle all eight of these gotchas correctly the first time, because the user never sees the code. The patterns above are exactly what we now bake into every generated bot at the template level.

If you're building a Discord bot from scratch, copy the snippets directly. They're worth a week of debugging each.

Frequently Asked Questions

What does Discord error 50013 mean?

It means "Missing Permissions" but almost always the cause is role hierarchy, not the permission bitfield. The bot must have a role positioned ABOVE the role of the user or role it is trying to manage. Move the bot's role up in Server Settings, Roles.

How do I fix "Unknown Interaction" (10062) errors?

Discord interactions expire 3 seconds after the user invokes them. If you need to do anything async (DB query, API call, LLM) call interaction.deferReply() first to buy yourself 15 minutes, then use interaction.editReply() once you have the response.

Why is message.content empty in my Discord bot?

You are missing the Message Content intent. Enable it in two places: (1) the Discord Developer Portal under your application's "Bot" tab, and (2) your client config's intents array (GatewayIntentBits.MessageContent). Both are required.

What is a partial message in discord.js?

A partial message is one where discord.js did not cache the full message body because the message predates the current bot session (often happens with reactions on older messages). Call message.fetch() before accessing its properties, and enable Partials.Message in your client config.

Can I edit an ephemeral reply later?

Yes, but only via the original interaction token, not by message ID. Call interaction.editReply() on the same interaction object. Ephemeral replies do not appear in channel.messages.fetch() and cannot be reacted to.

Ready to try VibeBot?

Join 2,500+ Discord servers using VibeBot for AI-powered bot building. Start with a 3-day free trial.

Explore VibeBot Features

Related Articles