Handle Discord Button Interactions in discord.js v14 Without Missing the Acknowledgment Deadline
Learn how to acknowledge Discord button clicks within the three-second window and scope MessageComponentCollector to a single message in discord.js v14.
31 Aug 2026, 16:18 UTC

The problem: button clicks that expire before the bot answers
A user clicks a button on your Discord message, and nothing happens. A few seconds later, Discord shows "Interaction failed" or "Unknown interaction." This usually means the bot received the interactionCreate event but did not acknowledge it within Discord's three-second deadline, or the event never arrived because of missing gateway intents.
Thesis: narrow the interaction type, acknowledge quickly, then scope the collector
In discord.js v14, component interactions such as button clicks arrive through the interactionCreate event. Your handler should narrow the event with interaction.isButton() before calling reply methods, acknowledge within three seconds using reply, deferReply, update, or deferUpdate, and use MessageComponentCollector when you need to wait for multiple clicks on the same message.
1. Acknowledge every interaction within three seconds
Discord expects an acknowledgment within 3,000 milliseconds. If you need time to look up data, call await interaction.deferReply() immediately. This tells Discord the interaction is being handled. You can edit the deferred response later. If you only need to refresh the message components without sending a new message, use await interaction.deferUpdate() instead.
Never call reply or deferReply more than once for the same interaction. A second response will throw an error because the interaction token is already consumed.
2. Use MessageComponentCollector for multi-click flows
MessageComponentCollector binds to a specific message and stops after a time limit, maximum interactions, or maximum users. It emits collect when a matching interaction arrives, dispose when a component is removed, and end when the collector stops. The filter function runs for every interaction on that message, so keep it lightweight to avoid blocking other event processing.
3. Confirm gateway intents before debugging missing events
If button interactions never reach your handler, check the client's GatewayIntentBits. Missing Guilds or GuildMembers can silently prevent message and interaction events from arriving. Compare your configuration against the discord.js intent reference for your installed version.
Worked example: previous and next buttons on an embed
Run this file with node button-collector.js in your project directory. The bot account needs Send Messages and Read Message History permissions in the test guild.
const { Client, GatewayIntentBits, Partials } = require('discord.js');
const client = new Client({
intents: [
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildMembers,
GatewayIntentBits.GuildMessages,
],
partials: [Partials.Message, Partials.Channel, Partials.Reaction],
});
client.on('interactionCreate', async (interaction) => {
if (!interaction.isButton()) return;
try {
// Acknowledge within Discord's three-second window.
await interaction.deferReply({ ephemeral: true });
const collector = interaction.message.createMessageComponentCollector({
filter: (i) => i.user.id === interaction.user.id,
time: 60000,
max: 5,
});
collector.on('collect', async (i) => {
if (i.customId === 'prev') {
// update embed page here
await i.deferUpdate();
} else if (i.customId === 'next') {
// update embed page here
await i.deferUpdate();
}
});
collector.on('end', (collected, reason) => {
console.log(`Collector ended: ${reason}; collected ${collected.size} interactions`);
});
} catch (error) {
console.error('Interaction handler error:', error);
}
});
client.login(process.env.DISCORD_TOKEN);
Expected check: run npm ls discord.js and confirm the installed major version is 14.x. Click a button in a test guild and confirm the console logs the collector end reason after the time or max limit. Clicks from other users should be ignored by the filter.
Limitation: custom_id values must survive redeploys
Button custom_id strings must remain stable across restarts if users can click buttons from messages sent before a redeploy. Changing the ID makes old buttons orphaned because the handler no longer recognizes them. Keep IDs in a constants file or database record rather than generating them dynamically per deploy.
Practical check: after a restart, click a button from a message sent before the restart and verify interaction.customId matches a branch in your collector filter.
Closing
Treat every Discord interaction as a three-second contract: acknowledge first, then do the work. Scope collectors to individual messages, keep filters cheap, and verify intents when events disappear. These patterns keep button-driven flows responsive even as your bot grows.
0 replies
A thoughtful contribution can make all the difference. Be the first to share one.