Class CommandClientBuilder

java.lang.Object
com.jagrosh.jdautilities.command.CommandClientBuilder

public class CommandClientBuilder extends Object
A simple builder used to create a CommandClientImpl.

Once built, add the CommandClient as an EventListener to JDA and it will automatically handle commands with ease!

Author:
John Grosh (jagrosh)
  • Constructor Details

    • CommandClientBuilder

      public CommandClientBuilder()
  • Method Details

    • build

      public CommandClient build()
      Builds a CommandClientImpl with the provided settings.
      Once built, only the CommandListener, and Commands can be changed.
      Returns:
      The CommandClient built.
    • setOwnerId

      public CommandClientBuilder setOwnerId(String ownerId)
      Sets the owner for the bot.
      Make sure to verify that the ID provided is ISnowflake compatible when setting this. If it is not, this will warn the developer.
      Parameters:
      ownerId - The ID of the owner.
      Returns:
      This builder
    • setOwnerId

      public CommandClientBuilder setOwnerId(long ownerId)
      Sets the owner for the bot.
      Make sure to verify that the ID provided is ISnowflake compatible when setting this. If it is not, this will warn the developer.
      Parameters:
      ownerId - The ID of the owner.
      Returns:
      This builder
    • setCoOwnerIds

      public CommandClientBuilder setCoOwnerIds(String... coOwnerIds)
      Sets the one or more CoOwners of the bot.
      Make sure to verify that all of the IDs provided are ISnowflake compatible when setting this. If it is not, this will warn the developer which ones are not.
      Parameters:
      coOwnerIds - The ID(s) of the CoOwners
      Returns:
      This builder
    • setCoOwnerIds

      public CommandClientBuilder setCoOwnerIds(long... coOwnerIds)
      Sets the one or more CoOwners of the bot.
      Make sure to verify that all of the IDs provided are ISnowflake compatible when setting this. If it is not, this will warn the developer which ones are not.
      Parameters:
      coOwnerIds - The ID(s) of the CoOwners
      Returns:
      This builder
    • setPrefix

      public CommandClientBuilder setPrefix(String prefix)
      Sets the bot's prefix.
      If set null, empty, or not set at all, the bot will use a mention @Botname as a prefix.
      Parameters:
      prefix - The prefix for the bot to use
      Returns:
      This builder
    • setAlternativePrefix

      public CommandClientBuilder setAlternativePrefix(String prefix)
      Sets the bot's alternative prefix.
      If set null, the bot will only use its primary prefix prefix.
      Parameters:
      prefix - The alternative prefix for the bot to use
      Returns:
      This builder
    • setPrefixes

      public CommandClientBuilder setPrefixes(String[] prefixes)
      Sets an array of prefixes in case it's not enough. Be careful.
      Parameters:
      prefixes - The prefixes to use
      Returns:
      This builder
    • setPrefixFunction

      public CommandClientBuilder setPrefixFunction(Function<net.dv8tion.jda.api.events.message.MessageReceivedEvent,String> prefixFunction)
      Sets the Prefix Function. Used if you want custom prefixes per server.
      Be careful, this function should be quick, as it's executed every time MessageReceivedEvent is called.
      If function returns null, it will be ignored.
      Parameters:
      prefixFunction - The prefix function to execute to use
      Returns:
      This builder
    • setCommandPreProcessFunction

      @Deprecated @DeprecatedSince("1.24.0") @ForRemoval(deadline="2.0") public CommandClientBuilder setCommandPreProcessFunction(Function<net.dv8tion.jda.api.events.message.MessageReceivedEvent,Boolean> commandPreProcessFunction)
      Deprecated.
      Please use setCommandPreProcessBiFunction(BiFunction) instead. You can simply add a new parameter for the command, it doesn't have to be used.
      Sets the pre-process function. This code is executed before every command.
      Returning "true" will allow processing to proceed.
      Returning "false" or "null" will prevent the Command from executing.
      Parameters:
      commandPreProcessFunction - The function to execute
      Returns:
      This builder
    • setCommandPreProcessBiFunction

      public CommandClientBuilder setCommandPreProcessBiFunction(BiFunction<net.dv8tion.jda.api.events.message.MessageReceivedEvent,Command,Boolean> commandPreProcessBiFunction)
      Sets the pre-process function. This code is executed before every command.
      Returning "true" will allow processing to proceed.
      Returning "false" or "null" will prevent the Command from executing.
      You can use Command to see which command will run.
      Parameters:
      commandPreProcessBiFunction - The function to execute
      Returns:
      This builder
    • useHelpBuilder

      public CommandClientBuilder useHelpBuilder(boolean useHelp)
      Sets whether the CommandClient will use the builder to automatically create a help command or not.
      Parameters:
      useHelp - false to disable the help command builder, otherwise the CommandClient will use either the default or one provided via setHelpConsumer(Consumer)}.
      Returns:
      This builder
    • setHelpConsumer

      public CommandClientBuilder setHelpConsumer(Consumer<CommandEvent> helpConsumer)
      Sets the consumer to run as the bot's help command.
      Setting it to null or not setting this at all will cause the bot to use the default help builder.
      Parameters:
      helpConsumer - A consumer to accept a CommandEvent when a help command is called.
      Returns:
      This builder
    • setHelpWord

      public CommandClientBuilder setHelpWord(String helpWord)
      Sets the word used to trigger the command list.
      Setting this to null or not setting this at all will set the help word to "help".
      Parameters:
      helpWord - The word to trigger the help command
      Returns:
      This builder
    • setServerInvite

      public CommandClientBuilder setServerInvite(String serverInvite)
      Sets the bot's support server invite.
      Parameters:
      serverInvite - The support server invite
      Returns:
      This builder
    • setEmojis

      public CommandClientBuilder setEmojis(String success, String warning, String error)
      Sets the emojis for success, warning, and failure.
      Parameters:
      success - Emoji for success
      warning - Emoji for warning
      error - Emoji for failure
      Returns:
      This builder
    • setActivity

      public CommandClientBuilder setActivity(net.dv8tion.jda.api.entities.Activity activity)
      Sets the Game to use when the bot is ready.
      Can be set to null for JDA Utilities to not set it.
      Parameters:
      activity - The Game to use when the bot is ready
      Returns:
      This builder
    • useDefaultGame

      public CommandClientBuilder useDefaultGame()
      Sets the Game the bot will use as the default: 'Playing Type [prefix]help'
      Returns:
      This builder
    • setStatus

      public CommandClientBuilder setStatus(net.dv8tion.jda.api.OnlineStatus status)
      Sets the OnlineStatus the bot will use once Ready This defaults to ONLINE
      Parameters:
      status - The status to set
      Returns:
      This builder
    • addCommand

      public CommandClientBuilder addCommand(Command command)
      Adds a Command and registers it to the CommandClientImpl for this session.
      Parameters:
      command - The command to add
      Returns:
      This builder
    • addCommands

      public CommandClientBuilder addCommands(Command... commands)
      Adds and registers multiple Commands to the CommandClientImpl for this session.
      This is the same as calling addCommand(Command) multiple times.
      Parameters:
      commands - The Commands to add
      Returns:
      This builder
    • addSlashCommand

      public CommandClientBuilder addSlashCommand(SlashCommand command)
      Adds a SlashCommand and registers it to the CommandClientImpl for this session.
      Parameters:
      command - The SlashCommand to add
      Returns:
      This builder
    • addSlashCommands

      public CommandClientBuilder addSlashCommands(SlashCommand... commands)
      Adds and registers multiple SlashCommands to the CommandClientImpl for this session.
      This is the same as calling addSlashCommand(SlashCommand) multiple times.
      Parameters:
      commands - The Commands to add
      Returns:
      This builder
    • addContextMenu

      public CommandClientBuilder addContextMenu(ContextMenu contextMenu)
      Adds a SlashCommand and registers it to the CommandClientImpl for this session.
      Parameters:
      contextMenu - The Context Menu to add
      Returns:
      This builder
    • addContextMenus

      public CommandClientBuilder addContextMenus(ContextMenu... contextMenus)
      Adds and registers multiple SlashCommands to the CommandClientImpl for this session.
      This is the same as calling addSlashCommand(SlashCommand) multiple times.
      Parameters:
      contextMenus - The Context Menus to add
      Returns:
      This builder
    • forceGuildOnly

      public CommandClientBuilder forceGuildOnly(String guildId)
      Forces Guild Only for SlashCommands. Setting this to null disables the feature, but it is off by default.
      Parameters:
      guildId - the guild ID.
      Returns:
      This Builder
    • forceGuildOnly

      public CommandClientBuilder forceGuildOnly(long guildId)
      Forces Guild Only for SlashCommands. Setting this to null disables the feature, but it is off by default.
      Parameters:
      guildId - the guild ID.
      Returns:
      This Builder
    • setManualUpsert

      public CommandClientBuilder setManualUpsert(boolean manualUpsert)
      Whether or not to manually upsert slash commands. This is designed if you want to handle upserting, instead of doing it every boot. False by default.
      Parameters:
      manualUpsert - your option.
      Returns:
      This Builder
    • addAnnotatedModule

      public CommandClientBuilder addAnnotatedModule(Object module)
      Adds an annotated command module to the CommandClientImpl for this session.

      For more information on annotated command modules, see the annotation package documentation.

      Parameters:
      module - The annotated command module to add
      Returns:
      This builder
      See Also:
    • addAnnotatedModules

      public CommandClientBuilder addAnnotatedModules(Object... modules)
      Adds multiple annotated command modules to the CommandClientImpl for this session.
      This is the same as calling addAnnotatedModule(Object) multiple times.

      For more information on annotated command modules, see the annotation package documentation.

      Parameters:
      modules - The annotated command modules to add
      Returns:
      This builder
      See Also:
    • setAnnotatedCompiler

      public CommandClientBuilder setAnnotatedCompiler(AnnotatedModuleCompiler compiler)
      Sets the AnnotatedModuleCompiler for this CommandClientBuilder.

      If not set this will be the default implementation found here.

      Parameters:
      compiler - The AnnotatedModuleCompiler to use
      Returns:
      This builder
      See Also:
    • setCarbonitexKey

      public CommandClientBuilder setCarbonitexKey(String key)
      Sets the Carbonitex key for this bot's listing.

      When set, the CommandClientImpl will automatically update it's Carbonitex listing with relevant information such as server count.

      Parameters:
      key - A Carbonitex key
      Returns:
      This builder
    • setDiscordBotsKey

      public CommandClientBuilder setDiscordBotsKey(String key)
      Sets the Discord Bots API key for this bot's listing.

      When set, the CommandClientImpl will automatically update it's Discord Bots listing with relevant information such as server count.

      This will also retrieve the bot's total guild count in the same request, which can be accessed via CommandClient.getTotalGuilds().

      Parameters:
      key - A Discord Bots API key
      Returns:
      This builder
    • setDiscordBotListKey

      @Deprecated public CommandClientBuilder setDiscordBotListKey(String key)
      Deprecated.
      This method has been deprecated as the new(ish) ratelimit system is more complex than we'd like to implement in JDA-Utils. Considering using some other library which correctly handles the ratelimits for this service.
      Parameters:
      key - A Discord Bot List API key
      Returns:
      This builder
    • setListener

      public CommandClientBuilder setListener(CommandListener listener)
      Parameters:
      listener - The CommandListener for the CommandClientImpl
      Returns:
      This builder
    • setScheduleExecutor

      public CommandClientBuilder setScheduleExecutor(ScheduledExecutorService executor)
      Parameters:
      executor - The ScheduledExecutorService for the CommandClientImpl
      Returns:
      This builder
    • setShutdownAutomatically

      public CommandClientBuilder setShutdownAutomatically(boolean shutdownAutomatically)
      Sets the Command Client to shut down internals automatically when a ShutdownEvent is received.
      Parameters:
      shutdownAutomatically - false to disable calling the shutdown method when a ShutdownEvent is received
      Returns:
      This builder
    • setLinkedCacheSize

      public CommandClientBuilder setLinkedCacheSize(int linkedCacheSize)
      Sets the internal size of the client's FixedSizeCache used for caching and pairing the bot's response Messages with the calling Message's ID.

      Higher cache size means that decay of cache contents will most likely occur later, allowing the deletion of responses when the call is deleted to last for a longer duration. However this also means larger memory usage.

      Setting 0 or negative will cause the client to not use linked caching at all.

      Parameters:
      linkedCacheSize - The maximum number of paired responses that can be cached, or <1 if the built CommandClient will not use linked caching.
      Returns:
      This builder
    • setGuildSettingsManager

      public CommandClientBuilder setGuildSettingsManager(GuildSettingsManager manager)
      Sets the GuildSettingsManager for the CommandClientImpl built using this builder.
      Parameters:
      manager - The GuildSettingsManager to set.
      Returns:
      This builder