Class ReplyableEvent<T extends GenericInteractionCreateEvent>

java.lang.Object
io.github.kaktushose.jdac.dispatching.events.Event<T>
io.github.kaktushose.jdac.dispatching.events.ReplyableEvent<T>
All Implemented Interfaces:
ISnowflake, Interaction
Direct Known Subclasses:
ModalEvent, ModalReplyableEvent

public abstract sealed class ReplyableEvent<T extends GenericInteractionCreateEvent> extends Event<T> permits ModalEvent, ModalReplyableEvent<T>

Subtype of Event that supports replying to the GenericInteractionCreateEvent with text messages.

You can either reply directly by using one of the reply methods, like reply(String, Entry...), or you can call with() to use a ConfigurableReply to append components or override reply settings from the ReplyConfig.

Example:

public void onInteraction(ReplayableEvent<?> event) {
    event.reply("Hello World");
}
See Also:
  • Constructor Details

    • ReplyableEvent

      public ReplyableEvent()
  • Method Details

    • deferReply

      public void deferReply()

      Acknowledge this interaction and defer the reply to a later time.

      This will send a <Bot> is thinking... message in chat that will be updated later. This will use the respective InteractionDefinition.ReplyConfig to set the ephemeral flag. If your initial deferred message is ephemeral it cannot be made non-ephemeral later. Use deferReply(boolean) to override the InteractionDefinition.ReplyConfig.

      You only have 3 seconds to acknowledge an interaction!

      When the acknowledgement is sent after the interaction expired, you will receive ErrorResponse.UNKNOWN_INTERACTION.

      Use reply(String, Entry...) to reply directly.

    • deferReply

      public abstract void deferReply(boolean ephemeral)

      Acknowledge this interaction and defer the reply to a later time.

      This will send a <Bot> is thinking... message in chat that will be updated later. This will use the passed boolean to set the ephemeral flag. If your initial deferred message is ephemeral it cannot be made non-ephemeral later. Use deferReply() to use the InteractionDefinition.ReplyConfig for the ephemeral flag.

      You only have 3 seconds to acknowledge an interaction!

      When the acknowledgement is sent after the interaction expired, you will receive ErrorResponse.UNKNOWN_INTERACTION.

      Use reply(String, Entry...) to reply directly.

      Parameters:
      ephemeral - yes
    • getButton

      public Button getButton(String button)

      Gets a Button based on the method name and transforms it into a JDA Button.

      The button will be linked to the current Runtime. This may be useful if you want to send a component without using the framework.

      Parameters:
      button - the name of the button defining method
      Returns:
      the JDA Button
    • getButton

      public Button getButton(Class<?> origin, String button)

      Gets a Button based on the method name and the given class and transforms it into a JDA Button.

      The button will be runtime-independent. This may be useful if you want to send a component without using the framework.

      Parameters:
      origin - the Class of the method
      button - the name of the button defining method
      Returns:
      the JDA Button
    • getSelectMenu

      public SelectMenu getSelectMenu(String menu)

      Gets a StringMenu or EntityMenu based on the method name and transforms it into a JDA SelectMenu.

      The select menu will be linked to the current Runtime. This may be useful if you want to send a component without using the framework.

      Parameters:
      menu - the name of the select menu
      Returns:
      the JDA SelectMenu
    • getSelectMenu

      public SelectMenu getSelectMenu(Class<?> origin, String menu)

      Gets a StringMenu or EntityMenu based on the method name and transforms it into a JDA SelectMenu.

      The select menu will be runtime-independent. This may be useful if you want to send a component without using the framework.

      Parameters:
      origin - the Class of the method
      menu - the name of the select menu
      Returns:
      the JDA SelectMenu
    • embed

      public Embed embed(String name)

      Gets an Embed based on the given name.

      Use findEmbed(String) if you cannot ensure that the Embed exists.

      Parameters:
      name - the name of the Embed
      Returns:
      the Embed
      Throws:
      IllegalArgumentException - if no Embed with the given name exists in the configured data sources
    • findEmbed

      public Optional<Embed> findEmbed(String name)

      Gets an Embed based on the given name and wraps it in an Optional.

      Use this instead of embed(String) if you cannot ensure that the Embed exists.

      Parameters:
      name - the name of the Embed
      Returns:
      an Optional holding the Embed or an empty Optional if an Embed with the given name doesn't exist
    • with

      public ConfigurableReply with()

      Entry point for configuring a reply.

      Returns a new ConfigurableReply that can be used to append components or override reply settings.

      Returns:
      a new ConfigurableReply
      See Also:
    • reply

      public Message reply(MessageTopLevelComponent component, Entry... placeholder)

      Acknowledgement of this event with V2 Components.

      Using V2 components removes the top-level component limit, and allows more components in total (40).

      They also allow you to use a larger choice of components, such as any component extending MessageTopLevelComponent, as long as they are compatible.

      The character limit for the messages also gets changed to 4000.

      This, however, comes with a few drawbacks:

      • You cannot send content, embeds, polls or stickers
      • It does not support voice messages
      • It does not support previewing files
      • URLs don't create embeds
      • You cannot switch this message back to not using Components V2 (you can however upgrade a message to V2)
      Parameters:
      component - the MessageTopLevelComponent to reply with
      placeholder - the placeholders to use. See PlaceholderResolver
    • reply

      public Message reply(Collection<MessageTopLevelComponent> components, Entry... placeholder)

      Acknowledgement of this event with V2 Components.

      Using V2 components removes the top-level component limit, and allows more components in total (40).

      They also allow you to use a larger choice of components, such as any component extending MessageTopLevelComponent, as long as they are compatible.

      The character limit for the messages also gets changed to 4000.

      This, however, comes with a few drawbacks:

      • You cannot send content, embeds, polls or stickers
      • It does not support voice messages
      • It does not support previewing files
      • URLs don't create embeds
      • You cannot switch this message back to not using Components V2 (you can however upgrade a message to V2)
      Parameters:
      components - a Collection of MessageTopLevelComponents to reply with
      placeholder - the placeholders to use. See PlaceholderResolver
    • reply

      public Message reply(String message, Entry... placeholder)
      Acknowledgement of this event with a text message.
      Parameters:
      message - the message to send or the localization key
      placeholder - the placeholders to use to perform localization, see [I18n#localize(Locale , String, Entry...) ]
      Returns:
      the Message that got created
      Implementation Requirements:

      Internally this method calls RestAction.complete(), thus the Message object can get returned directly.

      This might throw RuntimeExceptions if JDA fails to send the message.

    • reply

      public Message reply(MessageEmbed first, MessageEmbed... additional)
      Acknowledgement of this event with a MessageEmbed.
      Parameters:
      first - the MessageEmbed to send
      additional - additional MessageEmbeds to send
      Returns:
      the Message that got created
      Implementation Requirements:

      Internally this method calls RestAction.complete(), thus the Message object can get returned directly.

      This might throw RuntimeExceptions if JDA fails to send the message.

    • reply

      public Message reply(MessageCreateData message)
      Acknowledgement of this event with a MessageCreateData.
      Parameters:
      message - the MessageCreateData to send
      Returns:
      the Message that got created
      Implementation Requirements:

      Internally this method calls RestAction.complete(), thus the Message object can get returned directly.

      This might throw RuntimeExceptions if JDA fails to send the message.