Replies, buttons and forms
Respond on time and build controls without losing the reply’s audience.
Examples use the bot client from Your first bot.
Reply or defer
Acknowledge an interaction within three seconds with a message, a deferral or a form. Follow-ups are available for fifteen minutes, up to ten response records. Choose private or public at the first acknowledgement; the audience cannot change later.
Private replies are excluded from public chat history, search and notifications. In server channels, the bot still needs Send Messages.
bot.command('status', async interaction => {
await interaction.defer({ private: true });
const result = await loadStatus();
await interaction.reply(result);
});Edit your reply and send followups
editReply / edit_reply targets the first successful message response from this interaction. After deferring, it sends that first response. Followups have their own response IDs, which you can keep for later edits or deletion.
These operations expire after fifteen minutes and recheck the bot and original user’s current access. They cannot change the private/public audience. A component creates a new interaction; edit its original public message with the channel/DM message helper instead.
await interaction.defer({ private: true });
await interaction.editReply('Your export is ready.');
const extra = await interaction.followUp('The download expires tomorrow.');
await interaction.editFollowUp(extra.id, 'The download expires in 24 hours.');
await interaction.deleteFollowUp(extra.id);
await interaction.deleteReply();Open a form
Open a form as the initial response, before replying or deferring. A form has one to five text or paragraph fields. Submission creates a fresh interaction with a new three-second acknowledgement deadline.
await interaction.showModal({
customId: 'feedback', title: 'Your feedback',
fields: [{ name: 'message', label: 'What could be better?', type: 'paragraph', required: true, maxLength: 1000 }],
});
bot.on('interaction', async interaction => {
if (interaction.kind === 'form' && interaction.data.customId === 'feedback') {
const message = interaction.data.values.message;
await interaction.reply('Thanks for the feedback.', { private: true });
}
});