Class DeferrableInteractionEvent

Direct Known Subclasses:
ApplicationCommandInteractionEvent, ComponentInteractionEvent

@Experimental public class DeferrableInteractionEvent extends InteractionCreateEvent
Dispatched when a user in a guild interacts with an application command or component. It is recommended you use a subclass in your event listeners to access interaction-specific methods. Application command interactions like ChatInputInteractionEvent, UserInteractionEvent and MessageInteractionEvent are created through Discord REST API, while component interactions like ButtonInteractionEvent and SelectMenuInteractionEvent are added to a message as user interface. See a diagram below for the current event hierarchy for interactions.

You are required to respond to this interaction within a three-second window by using one of the following:

  • reply() to directly include a message
  • deferReply() to acknowledge without a message, typically to perform a background task and give the user a loading state until it is edited
After the initial response is complete, you can work with the interaction using the following methods: You can also work with followup messages using:

This is not directly dispatched by Discord, but is a utility specialization of InteractionCreateEvent.

See Also:
  • Constructor Details

  • Method Details

    • acknowledge

      @Deprecated public Mono<Void> acknowledge()
      Deprecated.
      use deferReply() instead
      Acknowledges the interaction indicating a response will be edited later. The user sees a loading state, visible to all participants in the invoking channel. For an "only you can see this" response, see acknowledgeEphemeral(), or to include a message, reply(String).withEphemeral(true)
      Returns:
      A Mono where, upon successful completion, emits nothing; acknowledging the interaction and indicating a response will be edited later. The user sees a loading state. If an error is received, it is emitted through the Mono.
    • deferReply

      public discord4j.core.spec.InteractionCallbackSpecDeferReplyMono deferReply()
      Acknowledges the interaction indicating a response will be edited later. The user sees a loading state, visible to all participants in the invoking channel. For an "only you can see this" response, add withEphemeral(true), or to include a message, reply(String).withEphemeral(true).

      After calling deferReply, you are not allowed to call other acknowledging or reply method and have to either work with the initial reply using getReply(), editReply(), deleteReply(), or using followup messages with createFollowup(), editFollowup(Snowflake) or deleteFollowup(Snowflake).

      Returns:
      A InteractionCallbackSpecDeferReplyMono where, upon successful completion, emits nothing; acknowledging the interaction and indicating a response will be edited later. The user sees a loading state. If an error is received, it is emitted through it.
    • deferReply

      public Mono<Void> deferReply(discord4j.core.spec.InteractionCallbackSpec spec)
      Acknowledges the interaction indicating a response will be edited later. The user sees a loading state, visible to all participants in the invoking channel.

      After calling deferReply, you are not allowed to call other acknowledging or reply method and have to either work with the initial reply using getReply(), editReply(), deleteReply(), or using followup messages with createFollowup(), editFollowup(Snowflake) or deleteFollowup(Snowflake).

      Parameters:
      spec - an immutable object that specifies how to build the reply message to the interaction
      Returns:
      A Mono where, upon successful completion, emits nothing; acknowledging the interaction and indicating a response will be edited later. The user sees a loading state. If an error is received, it is emitted through the Mono.
    • acknowledgeEphemeral

      @Deprecated public Mono<Void> acknowledgeEphemeral()
      Deprecated.
      Acknowledges the interaction indicating a response will be edited later. Only the invoking user sees a loading state.
      Returns:
      A Mono where, upon successful completion, emits nothing, acknowledging the interaction and indicating a response will be edited later. If an error is received, it is emitted through the Mono.
    • reply

      Deprecated.
      use reply(InteractionApplicationCommandCallbackSpec), reply(String) or reply() which offer an immutable approach to build specs
      Requests to respond to the interaction with a message.
      Parameters:
      spec - A Consumer that provides a "blank" LegacyInteractionApplicationCommandCallbackSpec to be operated on.
      Returns:
      A Mono where, upon successful completion, emits nothing; indicating the interaction response has been sent. If an error is received, it is emitted through the Mono.
    • reply

      public discord4j.core.spec.InteractionApplicationCommandCallbackReplyMono reply()
      Requests to respond to the interaction with a message. Properties specifying how to build the reply message to the interaction can be set via the withXxx methods of the returned InteractionApplicationCommandCallbackReplyMono.

      For component interactions, like buttons or select menus, this method will create a new message. If you want to modify the message the component is on, see ComponentInteractionEvent.edit() or ComponentInteractionEvent.deferEdit().

      After calling reply, you are not allowed to call other acknowledging or reply method and have to either work with the initial reply using getReply(), editReply(), deleteReply(), or using followup messages with createFollowup(), editFollowup(Snowflake) or deleteFollowup(Snowflake).

      Returns:
      A InteractionApplicationCommandCallbackReplyMono where, upon successful completion, emits nothing; indicating the interaction response has been sent. If an error is received, it is emitted through the InteractionApplicationCommandCallbackMono.
    • reply

      public discord4j.core.spec.InteractionApplicationCommandCallbackReplyMono reply(String content)
      Requests to respond to the interaction with a message initialized with the specified content. Properties specifying how to build the reply message to the interaction can be set via the withXxx methods of the returned InteractionApplicationCommandCallbackReplyMono.

      For component interactions, like buttons or select menus, this method will create a new message. If you want to modify the message the component is on, see ComponentInteractionEvent.edit() or ComponentInteractionEvent.deferEdit().

      After calling reply, you are not allowed to call other acknowledging or reply method and have to either work with the initial reply using getReply(), editReply(), deleteReply(), or using followup messages with createFollowup(), editFollowup(Snowflake) or deleteFollowup(Snowflake).

      Parameters:
      content - a string to populate the message with
      Returns:
      A InteractionApplicationCommandCallbackReplyMono where, upon successful completion, emits nothing; indicating the interaction response has been sent. If an error is received, it is emitted through the InteractionApplicationCommandCallbackMono.
    • reply

      public Mono<Void> reply(discord4j.core.spec.InteractionApplicationCommandCallbackSpec spec)
      Requests to respond to the interaction with a message.

      For component interactions, like buttons or select menus, this method will create a new message. If you want to modify the message the component is on, see ComponentInteractionEvent.edit() or ComponentInteractionEvent.deferEdit().

      After calling reply, you are not allowed to call other acknowledging or reply method and have to either work with the initial reply using getReply(), editReply(), deleteReply(), or using followup messages with createFollowup(), editFollowup(Snowflake) or deleteFollowup(Snowflake).

      Parameters:
      spec - an immutable object that specifies how to build the reply message to the interaction
      Returns:
      A Mono where, upon successful completion, emits nothing; indicating the interaction response has been sent. If an error is received, it is emitted through the Mono.
    • presentModal

      public discord4j.core.spec.InteractionPresentModalMono presentModal()
      Requests to respond to the interaction by presenting a modal for the user to fill out and submit. Once the user submits the modal, it will be received as a new ModalSubmitInteractionEvent. Properties specifying how to build the modal can be set via the withXxx methods of the returned InteractionPresentModalMono.
      Returns:
      A InteractionPresentModalMono where, upon successful completion, emits nothing; indicating the interaction response has been sent. If an error is received, it is emitted through the InteractionPresentModalMono.
    • presentModal

      public Mono<Void> presentModal(String title, String customId, Collection<LayoutComponent> components)
      Requests to respond to the interaction by presenting a modal for the user to fill out and submit. Once the user submits the modal, it will be received as a new ModalSubmitInteractionEvent.
      Parameters:
      title - The title of the modal
      customId - A developer defined ID for the modal
      components - A collection of components the modal should contain
      Returns:
      A Mono where, upon successful completion, emits nothing; indicating the interaction response has been sent. If an error is received, it is emitted through the Mono.
    • presentModal

      public Mono<Void> presentModal(discord4j.core.spec.InteractionPresentModalSpec spec)
      Requests to respond to the interaction by presenting a modal for the user to fill out and submit with the given spec contents. Once the user submits the modal, it will be received as a new ModalSubmitInteractionEvent.
      Parameters:
      spec - an immutable object that specifies how to present the modal window
      Returns:
      A Mono where, upon successful completion, emits nothing; indicating the interaction response has been sent. If an error is received, it is emitted through the Mono.
    • editReply

      public discord4j.core.spec.InteractionReplyEditMono editReply(String content)
      Edits the initial reply sent when accepting this interaction with the given message content.

      For component interactions, like buttons or select menus, this method modifies the message depending on the initial response method chosen: if deferReply() or reply() was used, the new message created with the reply; if ComponentInteractionEvent.edit() or ComponentInteractionEvent.deferEdit() was used, this method will modify the message the component is on.

      Parameters:
      content - a string to update the message with
      Returns:
      a InteractionReplyEditMono where, upon successful completion, emits the updated message. If an error is received, it is emitted through the InteractionReplyEditMono.
    • editReply

      public discord4j.core.spec.InteractionReplyEditMono editReply()
      Edits the initial reply sent when accepting this interaction. Properties specifying how to build the edit message request can be set via the withXxx methods of the returned InteractionReplyEditMono.

      For component interactions, like buttons or select menus, this method modifies the message depending on the initial response method chosen: if deferReply() or reply() was used, the new message created with the reply; if ComponentInteractionEvent.edit() or ComponentInteractionEvent.deferEdit() was used, this method will modify the message the component is on.

      By default, this method will append any file added through withFiles. To replace or remove individual attachments, use withAttachments along with Attachment objects from the original message you want to keep. It is not required to include the new files as Attachment objects.

      For example, to replace all previous attachments, provide an empty withAttachments and your files:

      
        event.editReply()
           .withContentOrNull("Replaced all attachments")
           .withFiles(getFile())
           .withComponents(row)
           .withAttachments();
       

      To replace a specific attachment, you need to pass the attachment details you want to keep. You could work from the original Message.getAttachments() list and pass it to withAttachments and your files. The following example removes only the first attachment:

      
        event.getReply()
           .flatMap(reply -> event.editReply()
                   .withContentOrNull("Replaced the first attachment")
                   .withFiles(getFile())
                   .withComponents(row)
                   .withAttachmentsOrNull(reply.getAttachments()
                           .stream()
                           .skip(1)
                           .collect(Collectors.toList())));
       

      To clear all attachments, provide an empty withAttachments:

      
        event.editReply()
           .withContentOrNull("Removed all attachments")
           .withComponents(row)
           .withAttachments();
       
      Returns:
      a InteractionReplyEditMono where, upon successful completion, emits the updated message. If an error is received, it is emitted through the InteractionReplyEditMono.
    • editReply

      public Mono<Message> editReply(discord4j.core.spec.InteractionReplyEditSpec spec)
      Edits the initial reply sent when accepting this interaction with the given spec contents.

      For component interactions, like buttons or select menus, this method modifies the message depending on the initial response method chosen: if deferReply() or reply() was used, the new message created with the reply; if ComponentInteractionEvent.edit() or ComponentInteractionEvent.deferEdit() was used, this method will modify the message the component is on.

      By default, this method will append any file added through withFiles. To replace or remove individual attachments, use withAttachment along with Attachment objects from the original message you want to keep. It is not required to include the new files as Attachment objects.

      See the docs for editReply() for examples and adapt them to a standalone spec.

      Parameters:
      spec - an immutable object that specifies how to edit the initial reply
      Returns:
      a Mono where, upon successful completion, emits the updated message. If an error is received, it is emitted through the Mono.
    • getReply

      public Mono<Message> getReply()
      Returns the initial reply to this interaction.
      Returns:
      a Mono where, upon successful completion, emits the initial reply message. If an error is received, it is emitted through the Mono.
    • deleteReply

      public Mono<Void> deleteReply()
      Deletes the initial reply to this interaction.
      Returns:
      a Mono where, upon successful initial reply deletion, emits nothing indicating completion. If an error is received, it is emitted through the Mono.
    • createFollowup

      public discord4j.core.spec.InteractionFollowupCreateMono createFollowup()
      Creates a follow-up message to this interaction. Properties specifying how to build the follow-up message can be set via the withXxx methods of the returned InteractionFollowupCreateMono.
      Returns:
      a InteractionFollowupCreateMono where, upon successful completion, emits the resulting follow-up message. If an error is received, it is emitted through the InteractionApplicationCommandCallbackMono.
    • createFollowup

      public discord4j.core.spec.InteractionFollowupCreateMono createFollowup(String content)
      Creates a follow-up message to this interaction with the given message content.
      Parameters:
      content - a string to populate the followup message with
      Returns:
      a InteractionFollowupCreateMono where, upon successful completion, emits the resulting follow-up message. If an error is received, it is emitted through the InteractionApplicationCommandCallbackMono.
    • createFollowup

      public Mono<Message> createFollowup(discord4j.core.spec.InteractionFollowupCreateSpec spec)
      Creates a follow-up message to this interaction.
      Parameters:
      spec - an immutable object that specifies how to build the follow-up message
      Returns:
      a Mono where, upon successful completion, emits the resulting follow-up message. If an error is received, it is emitted through the Mono.
    • editFollowup

      public discord4j.core.spec.InteractionFollowupEditMono editFollowup(Snowflake messageId)
      Edits a follow-up message to this interaction. Properties specifying how to edit the follow-up message can be set via the withXxx methods of the returned InteractionFollowupEditMono.
      Parameters:
      messageId - the follow-up message ID to edit
      Returns:
      a InteractionFollowupEditMono where, upon successful completion, emits the updated follow-up message. If an error is received, it is emitted through the InteractionFollowupEditMono.
    • editFollowup

      public Mono<Message> editFollowup(Snowflake messageId, discord4j.core.spec.InteractionReplyEditSpec spec)
      Edits a follow-up message to this interaction.
      Parameters:
      messageId - the follow-up message ID to edit
      spec - an immutable object that specifies how to build the edited follow-up message
      Returns:
      a Mono where, upon successful completion, emits the updated follow-up message. If an error is received, it is emitted through the Mono.
    • deleteFollowup

      public Mono<Void> deleteFollowup(Snowflake messageId)
      Delete a followup message created under this interaction.
      Parameters:
      messageId - the message ID to be deleted
      Returns:
      a Mono where, upon successful message deletion, returns a completion signal. If an error is received, it is emitted through the Mono.
    • getInteractionResponse

      public InteractionResponse getInteractionResponse()
      Returns a REST-only handler for common operations related to an interaction response associated with this event.
      Returns:
      a handler aggregating a collection of REST API methods to work with an interaction response
      See Also: