Class JDACommands

java.lang.Object
io.github.kaktushose.jdac.JDACommands

public final class JDACommands extends Object

The main entry point of the JDA-Commands framework. This class includes methods to manage the overall framework while running.

Instances of this class can be created by using one of the "start" or "builder" methods.

  • Method Details

    • start

      public static JDACommands start(JDA jda)

      Creates a new JDACommands instance and starts the frameworks, including scanning the classpath for annotated classes. This uses reflections for some functionality.

      If any exception while configuration/start of JDA-Commands is thrown, the JDA instance if shutdown per default. This can be configured by setting JDACBuilder.shutdownJDA(boolean) to false.

      Parameters:
      jda - the corresponding JDA instance
      Returns:
      a new JDACommands instance
    • start

      public static JDACommands start(ShardManager shardManager)

      Creates a new JDACommands instance and starts the frameworks, including scanning the classpath for annotated classes. This uses reflections for some functionality.

      If any exception while configuration/start of JDA-Commands is thrown, the JDA instance if shutdown per default. This can be configured by setting JDACBuilder.shutdownJDA(boolean) to false.

      Parameters:
      shardManager - the corresponding ShardManager instance
      Returns:
      a new JDACommands instance
    • builder

      public static JDACBuilder builder(JDA jda)
      Create a new builder.
      Parameters:
      jda - the corresponding JDA instance
      Returns:
      a new JDACBuilder
    • builder

      public static JDACBuilder builder(ShardManager shardManager)
      Create a new builder.
      Parameters:
      shardManager - the corresponding ShardManager instance
      Returns:
      a new JDACBuilder
    • shutdown

      public void shutdown()

      Shuts down this JDACommands instance, making it unable to receive any events from Discord. This will not unregister any slash commands.

      If JDACBuilder.shutdownJDA(boolean) is set to `true``, the underlying JDA or ShardManager instance will be shutdown too.

    • updateGuildCommands

      public void updateGuildCommands()
      Updates all slash commands that are registered with CommandScope.GUILD
    • updateGuildCommands

      public void updateGuildCommands(Collection<Guild> guilds)
      Updates all slash commands that are registered with CommandScope.GUILD for the given Guilds.
      Parameters:
      guilds - a Collection of guilds to update.
    • 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 message without using the framework.

      Parameters:
      button - the name of the button in the format `FullClassNameWithPackage.method``
      Returns:
      the JDA Button
    • getSelectMenu

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

      Gets a StringMenu or EntityMenu based on the method name and the given class 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 button in the format `FullClassNameWithPackage.method``
      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
    • introspection

      public JDACIntrospection introspection()
      Gets the JDACIntrospection instance with scope JDACScope.INITIALIZED.
      Returns:
      the JDACIntrospection instance
    • property

      public <T> T property(JDACProperty<T> property)

      Gets the value of a property.

      This is a shortcut for JDACommands#introscpection#get

      Type Parameters:
      T - the type of property
      Parameters:
      property - the JDACProperty description
      Returns:
      T