← Back to Blog •

Why your Discord bot says "The application did not respond"

By the Upbot team

You run a slash command, the loading dots spin for a few seconds, and Discord gives up with "The application did not respond". In your logs, at the same moment, there's a DiscordAPIError[10062]: Unknown interaction. Both messages describe the same thing from two sides: your bot did answer, but more than 3 seconds after Discord sent the interaction, and by then Discord had already thrown it away.

That 3-second window is the whole story. Discord expects a first response to every interaction (a reply, a deferred reply, a modal, autocomplete choices) within 3 seconds. Once you've sent that first response, the interaction token stays valid for 15 minutes, which is plenty of time to edit the reply or send follow-ups. Miss the first 3 seconds, though, and every call you make with that interaction afterwards fails with 10062.

Acknowledge first, work after #

Most of the time, the command does something slow before it answers: a database query, an API call, fetching a member to check a role. On a good day it takes 800 ms and nobody notices. On a busy evening it takes 3.2 seconds and users start seeing the error.

The fix is to defer before doing anything that can be slow. deferReply() tells Discord you've got the interaction, shows "Bot is thinking…" to the user, and gives you the 15 minutes.

import { MessageFlags } from 'discord.js';

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

    await interaction.deferReply({ flags: MessageFlags.Ephemeral });

    const stats = await loadStatsFromDatabase(interaction.guildId);

    await interaction.editReply(`You have ${stats.members} members.`);
});

Watch out for what sits above the defer. A permission check that reads the database, or a guild.members.fetch(), eats into the 3 seconds just as much as the command itself. Put deferReply() first, then check. For buttons and select menus, deferUpdate() does the same job without posting a new message.

Two interaction types can't be deferred at all. Autocomplete has to return its choices within the 3 seconds, so keep the options in memory or make the lookup cheap, rather than calling a slow API on every keystroke. Modals have to be the very first response, so you can't defer and then decide to show one. If a command might open a modal, make that decision before any await.

When your bot answers twice #

Sometimes 10062 travels with another error, 40060 Interaction has already been acknowledged. That one means two pieces of code tried to answer the same interaction. It happens when an error handler replies after the command already did, or when a collector and the main handler both react to the same button.

It also happens, more often than you'd think, when two copies of the bot are running with the same token. You started it locally to test something and forgot about it, or an old process survived a deploy. Both receive every interaction, the faster one answers, and the other one fails. Before going through your code, run pm2 list or check your host's panel.

For the error handler case, a small guard avoids answering twice:

async function safeReply(interaction, content) {
    if (interaction.deferred || interaction.replied) {
        return interaction.editReply(content);
    }

    return interaction.reply(content);
}

When even /ping times out #

If 10062 shows up on random commands, including trivial ones, the command probably isn't the problem. Node runs your handlers on a single thread: a heavy loop, a synchronous file read or a big JSON.parse somewhere else in the bot holds up every interaction queued behind it. It gets worse at peak hours and on an overloaded host.

You can see it by measuring how long the interaction took to reach your handler, before your code does anything:

client.on('interactionCreate', (interaction) => {
    const delay = Date.now() - interaction.createdTimestamp;

    if (delay > 1000) {
        console.warn(`Interaction ${interaction.id} reached the handler after ${delay} ms`);
    }
});

The number includes the clock difference between your server and Discord, so don't read too much into a single value. If it regularly climbs past a second, look at what else the bot does in the same process, and at its memory.

Some will still expire #

A restart in the middle of a command or a network blip will always cost you the odd interaction. Catch 10062 so it doesn't crash the bot or bury the rest of your logs:

import { RESTJSONErrorCodes } from 'discord.js';

try {
    await interaction.editReply(content);
} catch (error) {
    if (error.code !== RESTJSONErrorCodes.UnknownInteraction) {
        throw error;
    }
}

The hard part is knowing which commands are close to the limit, because users rarely report it. They just try again, then stop using the command. For discord.js bots, the Upbot SDK records the response time of every command, button, modal and autocomplete in a discord.js bot, at the median and the 95th percentile, and counts the interactions that never got an answer in time. If /stats sits at 2.6 seconds at p95, you'll know before it starts failing.

Ready to upgrade your monitoring?