Interaction
- class Interaction
An interaction received from Discord, including application commands, components, autocomplete requests, and modal submissions. Use the
is*()guards before reading fields that only exist for one interaction kind. Discord requires an initial response or defer within three seconds.Example
discord.on(discord.events.INTERACTION_CREATE, async (interaction) => { if (!interaction.isButton() || interaction.customId !== 'refresh') return; await interaction.update({ content: 'Refreshed.' }); });
Properties
Property
Type
Description
appPermissionsBitmask of the bot’s permissions (as a decimal string).
channelIdChannel ID the interaction occurred in, or
null.commandNameThe name of the invoked command, or
nullfor non-command interactions.componentTypeThe type of component (button, select, etc.), or
null.customIdThe custom ID of the component or modal, or
null.entitlementsEntitlements for this interaction (SKU purchases).
guildIdGuild ID the interaction occurred in, or
nullwhen Discord omits it.guildLocaleThe guild’s preferred locale, or
nullwhen Discord omits it.idDiscord snowflake ID.
localeThe preferred locale of the interacting user.
memberThe guild member who triggered the interaction, or
null.messageThe message the interaction was on (for component interactions), or
null.targetIdTarget ID for context menu interactions, or
null.tokenInteraction token used internally by reply and follow-up methods. Treat it as a credential: do not log or persist it.
typeThe type of interaction.
userUser included in this payload.
valuesstring[]
Selected values from select menus.
Methods
-
async Interaction.autocompleteReply(choices:
CommandChoice[]) Promise<void> Respond with autocomplete choices.
- Parameters:
choices: The list of autocomplete suggestions to show.
- async Interaction.defer(options: { ephemeral?: boolean; }) Promise<void>
Acknowledge the interaction and show a loading state. Call editReply after the long-running work finishes.
- Parameters:
options: Optional defer settings (e.g.
ephemeral).
- async Interaction.deferUpdate() Promise<void>
Acknowledge a component interaction without editing the message.
- async Interaction.deleteFollowup(messageId: string) Promise<void>
Delete a follow-up message.
- Parameters:
messageId: The ID of the follow-up message to delete.
- async Interaction.deleteReply(messageId: string) Promise<void>
Delete the initial reply.
- Parameters:
messageId: Specific message ID to delete (defaults to initial reply).
-
async Interaction.editReply(body: string |
EditMessageOptions, messageId: string) Promise<Message> Edit the initial reply to this interaction.
- Parameters:
body: New message content or edit options.
messageId: Specific message ID to edit (defaults to initial reply).
- Returns:
The edited message.
-
async Interaction.fetchReply(messageId: string) Promise<
Message> Fetch the initial reply.
- Parameters:
messageId: Specific message ID to fetch (defaults to initial reply).
- Returns:
The fetched message.
-
async Interaction.followup(body: string |
SendMessageOptions& { ephemeral?: boolean; }) Promise<Message> Send a follow-up message after the initial interaction reply.
- Parameters:
body: Message content or send options.
- Returns:
The sent message.
- Interaction.getCheckbox(customId: string) boolean
Get whether a checkbox is checked.
- Parameters:
customId: The custom ID of the checkbox.
- Returns:
trueif the checkbox is checked.
- Interaction.getCheckboxValues(customId: string) string[]
Get the values of all checked checkboxes in a checkbox group.
- Parameters:
customId: The custom ID of the checkbox group.
- Returns:
Array of checked checkbox values.
-
Interaction.getFile(customId: string)
Attachment| null Get the file attachment from a file upload component.
- Parameters:
customId: The custom ID of the file upload component.
- Returns:
The attachment, or
nullif not found.
-
Interaction.getFiles(customId: string)
Attachment[] Get all file attachments from a file upload component.
- Parameters:
customId: The custom ID of the file upload component.
- Returns:
Array of attachments.
-
Interaction.getOptions()
InteractionOptionParser Get a typed option parser for command options.
- Interaction.getRadioValue(customId: string) string | null
Get the selected value of a radio group.
- Parameters:
customId: The custom ID of the radio group.
- Returns:
The selected value, or
nullif not found.
- Interaction.getTextInput(customId: string) string | null
Get the value of a text input in a modal submission.
- Parameters:
customId: The custom ID of the text input component.
- Returns:
The input value, or
nullif not found.
-
Interaction.isAutocomplete() boolean (typeguard for
Interaction& { type: 4; }) Returns whether this interaction requests application-command autocomplete choices.
-
Interaction.isButton() boolean (typeguard for
Interaction& { componentType: 2; customId: string; message:Message| null; }) Checks whether this interaction came from a button component.
- Returns:
Whether the interaction matches this component type.
-
Interaction.isChannelSelect() boolean (typeguard for
Interaction& { componentType: 8; customId: string; }) Checks whether this interaction came from a channel select menu.
- Returns:
Whether the interaction matches this component type.
-
Interaction.isCommand() boolean (typeguard for
Interaction& { commandName: string; }) Returns whether this is an application-command interaction and narrows
commandName.
-
Interaction.isComponent() boolean (typeguard for
Interaction& { componentType:ComponentType; customId: string; }) Returns whether this came from a message or modal component and narrows its component fields.
-
Interaction.isMentionableSelect() boolean (typeguard for
Interaction& { componentType: 7; customId: string; }) Checks whether this interaction came from a mentionable select menu.
- Returns:
Whether the interaction matches this component type.
-
Interaction.isMessageContextMenu() boolean (typeguard for
Interaction& { commandName: string; targetId: string; type: 2; }) Returns whether this is a message context-menu command and narrows
targetId.
-
Interaction.isModalSubmit() boolean (typeguard for
Interaction& { customId: string; }) Returns whether this is a modal submission and narrows
customId.
-
Interaction.isRoleSelect() boolean (typeguard for
Interaction& { componentType: 6; customId: string; }) Checks whether this interaction came from a role select menu.
- Returns:
Whether the interaction matches this component type.
-
Interaction.isStringSelect() boolean (typeguard for
Interaction& { componentType: 3; customId: string; }) Checks whether this interaction came from a string select menu.
- Returns:
Whether the interaction matches this component type.
-
Interaction.isUserContextMenu() boolean (typeguard for
Interaction& { commandName: string; targetId: string; type: 2; }) Returns whether this is a user context-menu command and narrows
targetId.
-
Interaction.isUserSelect() boolean (typeguard for
Interaction& { componentType: 5; customId: string; }) Checks whether this interaction came from a user select menu.
- Returns:
Whether the interaction matches this component type.
-
async Interaction.reply(body: string |
InteractionReplyOptions& { wait?: false; }) Promise<void> Reply to this interaction (when
wait: trueis set, returns the created message). This consumes the initial interaction response. Use followup for later messages.- Parameters:
body: Message content or interaction reply options.
- async Interaction.showModal(modal: { components: Component[]; customId: string; title: string; }) Promise<void>
Show a modal to the user.
- Parameters:
modal: Modal configuration with title and components.
-
async Interaction.update(body: string |
InteractionReplyOptions) Promise<void> Update the original interaction message (for component interactions).
- Parameters:
body: Message content or interaction reply options.
-
async Interaction.autocompleteReply(choices: