Class CommandClientBuilder
CommandClientImpl
.
Once built, add the CommandClient
as an EventListener to
JDA
and it will automatically handle commands with ease!
- Author:
- John Grosh (jagrosh)
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionaddAnnotatedModule
(Object module) Adds an annotated command module to theCommandClientImpl
for this session.addAnnotatedModules
(Object... modules) Adds multiple annotated command modules to theCommandClientImpl
for this session.addCommand
(Command command) Adds aCommand
and registers it to theCommandClientImpl
for this session.addCommands
(Command... commands) Adds and registers multipleCommand
s to theCommandClientImpl
for this session.addContextMenu
(ContextMenu contextMenu) Adds aSlashCommand
and registers it to theCommandClientImpl
for this session.addContextMenus
(ContextMenu... contextMenus) Adds and registers multipleSlashCommand
s to theCommandClientImpl
for this session.addSlashCommand
(SlashCommand command) Adds aSlashCommand
and registers it to theCommandClientImpl
for this session.addSlashCommands
(SlashCommand... commands) Adds and registers multipleSlashCommand
s to theCommandClientImpl
for this session.build()
Builds aCommandClientImpl
with the provided settings.forceGuildOnly
(long guildId) Forces Guild Only for SlashCommands.forceGuildOnly
(String guildId) Forces Guild Only for SlashCommands.setActivity
(net.dv8tion.jda.api.entities.Activity activity) Sets theGame
to use when the bot is ready.setAlternativePrefix
(String prefix) Sets the bot's alternative prefix.setAnnotatedCompiler
(AnnotatedModuleCompiler compiler) Sets theAnnotatedModuleCompiler
for this CommandClientBuilder.setCarbonitexKey
(String key) Sets the Carbonitex key for this bot's listing.setCommandPreProcessBiFunction
(BiFunction<net.dv8tion.jda.api.events.message.MessageReceivedEvent, Command, Boolean> commandPreProcessBiFunction) Sets the pre-process function.setCommandPreProcessFunction
(Function<net.dv8tion.jda.api.events.message.MessageReceivedEvent, Boolean> commandPreProcessFunction) Deprecated.setCoOwnerIds
(long... coOwnerIds) Sets the one or more CoOwners of the bot.setCoOwnerIds
(String... coOwnerIds) Sets the one or more CoOwners of the bot.Deprecated.setDiscordBotsKey
(String key) Sets the Discord Bots API key for this bot's listing.Sets the emojis for success, warning, and failure.Sets theGuildSettingsManager
for the CommandClientImpl built using this builder.setHelpConsumer
(Consumer<CommandEvent> helpConsumer) Sets the consumer to run as the bot's help command.setHelpWord
(String helpWord) Sets the word used to trigger the command list.setLinkedCacheSize
(int linkedCacheSize) Sets the internal size of the client'sFixedSizeCache
used for caching and pairing the bot's responseMessage
s with the calling Message's ID.setListener
(CommandListener listener) Sets theCommandListener
for theCommandClientImpl
.setManualUpsert
(boolean manualUpsert) Whether or not to manually upsert slash commands.setOwnerId
(long ownerId) Sets the owner for the bot.setOwnerId
(String ownerId) Sets the owner for the bot.Sets the bot's prefix.setPrefixes
(String[] prefixes) Sets an array of prefixes in case it's not enough.setPrefixFunction
(Function<net.dv8tion.jda.api.events.message.MessageReceivedEvent, String> prefixFunction) Sets the Prefix Function.setScheduleExecutor
(ScheduledExecutorService executor) Sets theScheduledExecutorService
for theCommandClientImpl
.setServerInvite
(String serverInvite) Sets the bot's support server invite.setShutdownAutomatically
(boolean shutdownAutomatically) Sets the Command Client to shut down internals automatically when aShutdownEvent
is received.setStatus
(net.dv8tion.jda.api.OnlineStatus status) Sets theOnlineStatus
the bot will use once Ready This defaults to ONLINESets theGame
the bot will use as the default: 'Playing Type [prefix]help'useHelpBuilder
(boolean useHelp) Sets whether theCommandClient
will use the builder to automatically create a help command or not.
-
Constructor Details
-
CommandClientBuilder
public CommandClientBuilder()
-
-
Method Details
-
build
Builds aCommandClientImpl
with the provided settings.
Once built, only theCommandListener
, andCommand
s can be changed.- Returns:
- The CommandClient built.
-
setOwnerId
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
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
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
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
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
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
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 usesetCommandPreProcessBiFunction(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
Sets whether theCommandClient
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 viasetHelpConsumer(Consumer)
}.- Returns:
- This builder
-
setHelpConsumer
Sets the consumer to run as the bot's help command.
Setting it tonull
or not setting this at all will cause the bot to use the default help builder.- Parameters:
helpConsumer
- A consumer to accept aCommandEvent
when a help command is called.- Returns:
- This builder
-
setHelpWord
Sets the word used to trigger the command list.
Setting this tonull
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
Sets the bot's support server invite.- Parameters:
serverInvite
- The support server invite- Returns:
- This builder
-
setEmojis
Sets the emojis for success, warning, and failure.- Parameters:
success
- Emoji for successwarning
- Emoji for warningerror
- Emoji for failure- Returns:
- This builder
-
setActivity
Sets theGame
to use when the bot is ready.
Can be set tonull
for JDA Utilities to not set it.- Parameters:
activity
- The Game to use when the bot is ready- Returns:
- This builder
-
useDefaultGame
Sets theGame
the bot will use as the default: 'Playing Type [prefix]help'- Returns:
- This builder
-
setStatus
Sets theOnlineStatus
the bot will use once Ready This defaults to ONLINE- Parameters:
status
- The status to set- Returns:
- This builder
-
addCommand
Adds aCommand
and registers it to theCommandClientImpl
for this session.- Parameters:
command
- The command to add- Returns:
- This builder
-
addCommands
Adds and registers multipleCommand
s to theCommandClientImpl
for this session.
This is the same as callingaddCommand(Command)
multiple times.- Parameters:
commands
- The Commands to add- Returns:
- This builder
-
addSlashCommand
Adds aSlashCommand
and registers it to theCommandClientImpl
for this session.- Parameters:
command
- The SlashCommand to add- Returns:
- This builder
-
addSlashCommands
Adds and registers multipleSlashCommand
s to theCommandClientImpl
for this session.
This is the same as callingaddSlashCommand(SlashCommand)
multiple times.- Parameters:
commands
- The Commands to add- Returns:
- This builder
-
addContextMenu
Adds aSlashCommand
and registers it to theCommandClientImpl
for this session.- Parameters:
contextMenu
- The Context Menu to add- Returns:
- This builder
-
addContextMenus
Adds and registers multipleSlashCommand
s to theCommandClientImpl
for this session.
This is the same as callingaddSlashCommand(SlashCommand)
multiple times.- Parameters:
contextMenus
- The Context Menus to add- Returns:
- This builder
-
forceGuildOnly
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
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
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
Adds an annotated command module to theCommandClientImpl
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
Adds multiple annotated command modules to theCommandClientImpl
for this session.
This is the same as callingaddAnnotatedModule(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
Sets theAnnotatedModuleCompiler
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
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
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.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
Sets theCommandListener
for theCommandClientImpl
.- Parameters:
listener
- The CommandListener for the CommandClientImpl- Returns:
- This builder
-
setScheduleExecutor
Sets theScheduledExecutorService
for theCommandClientImpl
.- Parameters:
executor
- The ScheduledExecutorService for the CommandClientImpl- Returns:
- This builder
-
setShutdownAutomatically
Sets the Command Client to shut down internals automatically when aShutdownEvent
is received.- Parameters:
shutdownAutomatically
-false
to disable calling the shutdown method when a ShutdownEvent is received- Returns:
- This builder
-
setLinkedCacheSize
Sets the internal size of the client'sFixedSizeCache
used for caching and pairing the bot's responseMessage
s 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 builtCommandClient
will not use linked caching.- Returns:
- This builder
-
setGuildSettingsManager
Sets theGuildSettingsManager
for the CommandClientImpl built using this builder.- Parameters:
manager
- The GuildSettingsManager to set.- Returns:
- This builder
-
setCommandPreProcessBiFunction(BiFunction)
instead.