Class MessageReply

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

public sealed class MessageReply extends Object permits ConfigurableReply, SendableReply
Handles all the business logic for sending messages, including embeds or V1 components.
  • Field Details

    • replyAction

      protected final ReplyAction replyAction
  • Constructor Details

  • Method Details

    • 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.

    • builder

      public SendableReply builder(Consumer<MessageCreateBuilder> consumer)

      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!");
      
      Parameters:
      consumer - the Consumer to access the MessageCreateBuilder
      Returns:
      this instance for fluent interface
    • 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:
      this instance for fluent interface
    • 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:
      this instance for fluent interface
    • 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:
      this instance for fluent interface
    • 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:
      this instance for fluent interface
    • 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!");
          }
       }
      
    • 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!");
          }
       }
      
      See Also:
    • resolver

      protected ComponentReplacer resolver()