Interaction is what you answer with: the interaction of a command is a CommandInteraction, the one of a button or a menu a ComponentInteraction, the one of a form a ModalInteraction. Discord wants a first answer within 3 seconds, and accepts edits and other messages for 15 minutes.
You never create an interaction: your
run function receives one. This page lists everything it has; how to answer well (when to defer, ephemeral answers, what happens when run throws) is in Answering.Properties
Whether
defer() was called and the answer is still to come. Also true after deferUpdate(), until update() or reply() completes it.CommandInteraction
Someone used a slash command. It has everything above, plus: And one more action,showModal().
ComponentInteraction
Someone clicked a button or picked something in a select menu of a message of the bot. It can answer like a command, or change the message the component is on. It has everything ofInteraction, plus:
And three more actions: update(), deferUpdate() and showModal().
Discord documentation
ModalInteraction
Someone sent a form of the bot. It can answer like a command; when a button or a menu opened the form, it can also change their message. It has everything ofInteraction, plus:
And two more actions: update() and deferUpdate(), which throw when message is null: “This form was opened by a command, not by a button or a menu: there is no message to change. Use interaction.reply().”
Discord documentation
In a server, in private
What a command receives is more precise thanCommandInteraction, and follows the where of the command. The same holds for components, with the InGuild, InPrivate and InDm types.
With
where: 'both', run receives GuildCommandInteraction | PrivateCommandInteraction: one if (interaction.guild) narrows everything.
Discord documentation
Helpers
toJSON()
console.log(interaction) never shows it either.
Actions
Answers are sent one after the other, in the order they were asked: you can callreply() and followUp() without waiting for the first to finish.
reply()
defer() was called (by you, or by the framework because the answer was taking long), this completes the pending answer.
Throws when the interaction was already answered: “This interaction was already answered. Use interaction.followUp() to send another message, or interaction.edit() to change the answer.”
Discord documentation
defer()
reply() can then take up to 15 minutes. The framework does it by itself when an answer takes long; call it yourself to choose when.
Does nothing when the interaction was already answered or deferred. Whether the answer is ephemeral is decided here: without ephemeral, it is what the command says.
update()
ComponentInteraction and a ModalInteraction. Changes the message the component is on, as the answer: its text, its embeds, its components, its files. Only what you pass changes; components: [] removes the buttons and menus.
Throws when the interaction was already answered with a message or deferred with defer(): “This interaction was already answered: the message can no longer be changed through it. Use interaction.message.edit() to change the message, or interaction.followUp() to send another one.”
Discord documentation
deferUpdate()
ComponentInteraction and a ModalInteraction. Tells Discord the message will change later: the person sees nothing meanwhile, and update() can then take up to 15 minutes. The framework does it by itself when an answer to a component takes long.
After deferUpdate(), reply() sends its message as a follow-up, which looks the same to the person, and edit() changes the message of the component.
showModal()
CommandInteraction and a ComponentInteraction. Opens a form, as the answer: showModal(report({ userId })), with a form declared with modal(). It must be the first answer, and the person has as long as they want to fill it in.
Throws when something was already answered: “A form can only be the first answer to an interaction: call interaction.showModal() before reply() or defer(), and the framework waits for it.”
Discord documentation
edit()
followUp()
delete()
Types
InteractionReply
reply() and followUp() take.
InteractionReplyOptions
The options of an answer: everything a message takes, exceptreplyTo and stickers, plus ephemeral. It is listed in InteractionReplyOptions.