Class ConfigurableReply

java.lang.Object
io.github.kaktushose.jdac.dispatching.reply.ConfigurableReply
Direct Known Subclasses:
SendableReply

public sealed class ConfigurableReply extends Object permits SendableReply

Builder for sending messages based on a GenericInteractionCreateEvent that supports adding components to messages and changing the InteractionDefinition.ReplyConfig.

Example:

@Interaction
public class ExampleCommand {

    @SlashCommand(value= "example command")
    public void onCommand(CommandEvent event){
        event.with().components(buttons("onButton")).reply("Hello World");
    }

    @Button("Press me!")
    public void onButton(ComponentEvent event){
        event.reply("You pressed me!");
    }
}
  • Field Details

    • replyAction

      protected final ReplyAction replyAction
  • Constructor Details

    • ConfigurableReply

      public ConfigurableReply(ReplyAction replyAction)
      Constructs a new ConfigurableReply.
      Parameters:
      replyAction - the underlying ReplyAction
    • ConfigurableReply

      public ConfigurableReply(ConfigurableReply configurableReply)
      Constructs a new ConfigurableReply.
      Parameters:
      configurableReply - the ConfigurableReply to copy
  • Method Details

    • ephemeral

      public ConfigurableReply ephemeral(boolean ephemeral)

      Whether to send ephemeral replies. Default value is false.

      Ephemeral messages have some limitations and will be removed once the user restarts their client. Limitations:

      • Cannot contain any files/ attachments
      • Cannot be reacted to
      • Cannot be retrieved

      This will override both JDACBuilder.globalReplyConfig(InteractionDefinition.ReplyConfig) and any ReplyConfig annotation!

      Parameters:
      ephemeral - true if to send ephemeral replies
      Returns:
      the current instance for fluent interface
    • editReply

      public ConfigurableReply editReply(boolean editReply)

      Whether to keep the original components when editing a message. Default value is true.

      More formally, if editing a message and keepComponents is true, the original message will first be queried and its components get added to the reply before it is sent.

      This will override both JDACBuilder.globalReplyConfig(InteractionDefinition.ReplyConfig) and any ReplyConfig annotation!

      Parameters:
      editReply - true if to keep the original components
      Returns:
      the current instance for fluent interface
    • keepComponents

      public ConfigurableReply keepComponents(boolean keepComponents)

      Whether to edit the original message or to send a new one. Default value is true.

      The original message is always the very first reply that was sent. E.g. for a slash command event, which was replied to with a text message and a button, the original message is that very reply.

      Subsequent replies to the same slash command event or the button event cannot be edited.

      This will override both JDACBuilder.globalReplyConfig(InteractionDefinition.ReplyConfig) and any ReplyConfig annotation!

      Parameters:
      keepComponents - true if to edit the original method
      Returns:
      the current instance for fluent interface
    • keepSelections

      public ConfigurableReply keepSelections(boolean keepSelections)
      Whether to keep the selections of a string select menu when sending edits. This setting only has an effect with keepComponents(boolean) true.
    • builder

      public ConfigurableReply builder(Consumer<MessageCreateBuilder> builder)

      Access the underlying MessageCreateBuilder for configuration steps not covered by ConfigurableReply.

      This method exposes the internal MessageCreateBuilder used by JDA-Commands. Modifying fields that are also manipulated by the Reply API, like content or embeds, may lead to unexpected behaviour.

      Example:
      event.with().builder(builder -> builder.setFiles(myFile)).reply("Hello World!");
      
    • 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 must call RestAction.complete(), thus the Message object can get returned directly.

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

    • embeds

      public SendableReply embeds(String... embeds)

      Acknowledgement of this event with one or more Embeds.

      Resolves the Embeds based on the given names. See EmbedConfig for more information.

      Parameters:
      embeds - the name of the Embeds to send
      Returns:
      a new SendableReply
    • embeds

      public SendableReply embeds(Embed... embeds)

      Acknowledgement of this event with one or more Embeds.

      See EmbedConfig for more information.

      Parameters:
      embeds - the Embeds to send
      Returns:
      a new SendableReply
    • embeds

      public SendableReply embeds(String embed, Consumer<Embed> consumer)

      Acknowledgement of this event with an Embed.

      Resolves the Embed based on the given name. See EmbedConfig for more information.

      Parameters:
      embed - the name of the Embed to send
      consumer - a Consumer allowing direct modification of the Embed before sending it.
      Returns:
      a new SendableReply
    • embeds

      public SendableReply embeds(String embed, Entry entry, Entry... entries)

      Acknowledgement of this event with an Embed.

      Resolves the Embed based on the given name. See EmbedConfig for more information.

      Parameters:
      embed - the name of the Embed to send
      entry - the placeholders to use. See Embed.placeholders(Entry...)
      entries - the placeholders to use. See Embed.placeholders(Entry...)
      Returns:
      a new SendableReply
    • components

      public SendableReply components(String... components)

      Adds an ActionRow to the reply and adds the passed components to it.

      The components will always be enabled and runtime-bound. Use components(Component...) if you want to modify these settings.

      The components must be defined in the same class where this method gets called!

      Example:
       @Interaction
       public class ExampleCommand {
      
          @SlashCommand(value= "example command")
          public void onCommand(CommandEvent event){
              event.with().components("onButton").reply("Hello World");
          }
      
          @Button("Press me!")
          public void onButton(ComponentEvent event){
              event.reply("You pressed me!");
          }
       }
      
      Parameters:
      components - the name of the components to add
      Returns:
      the current instance for fluent interface
    • components

      public SendableReply components(Component<?,?,?,?>... components)

      Adds an ActionRow to the reply and adds the passed Component to it.

      Example:
       @Interaction
       public class ExampleCommand {
      
          @SlashCommand(value= "example command")
          public void onCommand(CommandEvent event){
              event.with().components(Components.disabled("onButton")).reply("Hello World");
          }
      
          @Button("Press me!")
          public void onButton(ComponentEvent event){
              event.reply("You pressed me!");
          }
       }
      
      Parameters:
      components - the Component to add
      Returns:
      the current instance for fluent interface
      See Also: