public class CommandEngine extends net.dv8tion.jda.api.hooks.ListenerAdapter implements ICommandEngine
| Modifier | Constructor and Description |
|---|---|
protected |
CommandEngine()
Creates an Instance of this
ICommandEngine implementations. |
| Modifier and Type | Method and Description |
|---|---|
ICommandEngine |
addAlias(@NotNull String name,
ICommand command)
Add an alternative name to a command.
|
ICommandEngine |
addCommand(@NotNull ICommand command)
Registers an ICommand into the engine.
|
static void |
addCommandPackage(String path)
Set the package name where the classes that extends ICommand are located in your project.
|
static @NotNull net.dv8tion.jda.api.JDA |
create(@NotNull net.dv8tion.jda.api.JDABuilder builder)
This will build the JDA object.
|
static @NotNull net.dv8tion.jda.api.JDA |
create(String token,
Collection<net.dv8tion.jda.api.requests.GatewayIntent> intents)
Creates a JDA with the predefined token.
|
static @NotNull net.dv8tion.jda.api.JDA |
create(String token,
net.dv8tion.jda.api.requests.GatewayIntent intent,
net.dv8tion.jda.api.requests.GatewayIntent... intents)
Creates a JDA with the predefined token.
|
static @NotNull net.dv8tion.jda.api.JDA |
createDefault(String token)
Creates a JDABuilder with recommended default settings.
|
static @NotNull net.dv8tion.jda.api.JDA |
createDefault(String token,
Collection<net.dv8tion.jda.api.requests.GatewayIntent> intents)
Creates a JDABuilder with recommended default settings.
|
static @NotNull net.dv8tion.jda.api.JDA |
createDefault(String token,
net.dv8tion.jda.api.requests.GatewayIntent intent,
net.dv8tion.jda.api.requests.GatewayIntent... intents)
Creates a JDABuilder with recommended default settings.
|
static @NotNull net.dv8tion.jda.api.JDA |
createLight(String token)
Creates a JDA with low memory profile settings and with ICommandEngine preset.
|
static @NotNull net.dv8tion.jda.api.JDA |
createLight(String token,
Collection<net.dv8tion.jda.api.requests.GatewayIntent> intents)
Creates a JDA with low memory profile settings and with ICommandEngine preset.
|
static @NotNull net.dv8tion.jda.api.JDA |
createLight(String token,
net.dv8tion.jda.api.requests.GatewayIntent intent,
net.dv8tion.jda.api.requests.GatewayIntent... intents)
Creates a JDA with low memory profile settings and with ICommandEngine preset.
|
@Nullable ICommand |
getCommand(@NotNull String name)
Get an ICommand from the registered commands in the Engine.
|
@NotNull @UnmodifiableView List<ICommand> |
getCommands()
Get a list of
ICommand registered in the Engine. |
@NotNull List<ICommand> |
getCommandsByExactMatch(String name)
Get a list of ICommand from the registered commands in the Engine.
|
@NotNull List<ICommand> |
getCommandsByPartialMatch(String name)
Get a list of ICommand from the registered commands in the Engine.
|
ICommand |
getHelpCommand()
Return the ICommand object of the help command.
|
static ICommandEngine |
getInstance()
Get the actual instance of
ICommandEngine that is being used. |
net.dv8tion.jda.api.JDA |
getJda()
Get the JDA object set within this Engine.
|
Locale |
getLanguage()
Gets the default language to be used by the bot.
|
Locale |
getLanguage(@Nullable net.dv8tion.jda.api.events.Event event)
By default, gets the default language to be used by the bot.
|
String |
getPrefix()
Gets the prefix configured on the bot.
|
String |
getPrefix(@NotNull net.dv8tion.jda.api.events.Event event)
By default, it gets the prefix configured on the bot.
|
String |
getPrefix(@NotNull net.dv8tion.jda.api.events.message.MessageReceivedEvent event)
By default, it gets the prefix configured on the bot.
|
String |
getPrefix(@NotNull net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent event)
By default, it gets the prefix configured on the bot.
|
IRepository |
getRepository()
Return the repository Controller.
|
@NotNull String |
getString(@NotNull String key)
Gets a text string in the configured language of the bot.
|
@NotNull String |
getString(@NotNull String key,
@NotNull Locale locale)
Gets a text string in a specific language.
|
@NotNull String[] |
getStringArray(@NotNull String key)
Gets a string Array in the configured language of the bot.
|
@NotNull String[] |
getStringArray(@NotNull String key,
@NotNull Locale locale)
Gets a string Array in a specific language.
|
static void |
includeBuildInUtils()
Include pre-created commands, such has Help, Ping, Language and prefix.
|
boolean |
isReactToMention()
Get whether the bot should react to mention or not.
|
boolean |
isReactToMention(net.dv8tion.jda.api.events.Event event)
Checks if bot should react to mention calls (Messages that starts with @BOT_NAME).
|
void |
loadCommands()
Registers ICommands from packages set into the engine.
|
void |
logDebug(String message)
Log a message at the DEBUG level.
|
void |
logError(String message)
Log a message at the ERROR level.
|
void |
logInfo(String message)
Log a message at the INFO level.
|
void |
logWarn(String message)
Log a message at the WARN level.
|
void |
onMessageReceived(@NotNull net.dv8tion.jda.api.events.message.MessageReceivedEvent event) |
void |
onSlashCommandInteraction(@NotNull net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent event) |
ICommandEngine |
setHelp(String help)
Set which command is related to user help.
|
static void |
setInstance(ICommandEngine newCommandConfig)
Set a custom implementation of
ICommandEngine. |
ICommandEngine |
setJda(net.dv8tion.jda.api.JDA jda)
Set the JDA instance of the bot.
|
ICommandEngine |
setLanguage(@NotNull Locale language)
Sets the default language to be used by the bot.
|
ICommandEngine |
setPrefix(@NotNull net.dv8tion.jda.api.entities.Guild guild,
@NotNull String prefix)
Sets a prefix for a specific guild.
|
ICommandEngine |
setPrefix(@NotNull String prefix)
Sets the default prefix for the bot.
|
ICommandEngine |
setReactToMention(boolean reactToMention)
Sets if the bot should react to a message starting by mentioning the bot @bot_name
if sets to false, the bot will only react to prefix.
|
static void |
setRepository(IRepository repository) |
onApplicationCommandUpdatePrivileges, onApplicationUpdatePrivileges, onButtonInteraction, onChannelCreate, onChannelDelete, onChannelUpdateArchived, onChannelUpdateArchiveTimestamp, onChannelUpdateAutoArchiveDuration, onChannelUpdateBitrate, onChannelUpdateInvitable, onChannelUpdateLocked, onChannelUpdateName, onChannelUpdateNSFW, onChannelUpdateParent, onChannelUpdatePosition, onChannelUpdateRegion, onChannelUpdateSlowmode, onChannelUpdateTopic, onChannelUpdateType, onChannelUpdateUserLimit, onCommandAutoCompleteInteraction, onDisconnect, onEmojiAdded, onEmojiRemoved, onEmojiUpdateName, onEmojiUpdateRoles, onEvent, onException, onGatewayPing, onGenericAutoCompleteInteraction, onGenericChannel, onGenericChannelUpdate, onGenericCommandInteraction, onGenericComponentInteractionCreate, onGenericContextInteraction, onGenericEmoji, onGenericEmojiUpdate, onGenericEvent, onGenericGuild, onGenericGuildInvite, onGenericGuildMember, onGenericGuildMemberUpdate, onGenericGuildSticker, onGenericGuildStickerUpdate, onGenericGuildUpdate, onGenericGuildVoice, onGenericInteractionCreate, onGenericMessage, onGenericMessageReaction, onGenericPermissionOverride, onGenericPrivilegeUpdate, onGenericRole, onGenericRoleUpdate, onGenericSelfUpdate, onGenericStageInstance, onGenericStageInstanceUpdate, onGenericThread, onGenericThreadMember, onGenericUpdate, onGenericUser, onGenericUserPresence, onGuildAvailable, onGuildBan, onGuildInviteCreate, onGuildInviteDelete, onGuildJoin, onGuildLeave, onGuildMemberJoin, onGuildMemberRemove, onGuildMemberRoleAdd, onGuildMemberRoleRemove, onGuildMemberUpdate, onGuildMemberUpdateAvatar, onGuildMemberUpdateBoostTime, onGuildMemberUpdateNickname, onGuildMemberUpdatePending, onGuildMemberUpdateTimeOut, onGuildReady, onGuildStickerAdded, onGuildStickerRemoved, onGuildStickerUpdateAvailable, onGuildStickerUpdateDescription, onGuildStickerUpdateName, onGuildStickerUpdateTags, onGuildTimeout, onGuildUnavailable, onGuildUnban, onGuildUpdateAfkChannel, onGuildUpdateAfkTimeout, onGuildUpdateBanner, onGuildUpdateBoostCount, onGuildUpdateBoostTier, onGuildUpdateCommunityUpdatesChannel, onGuildUpdateDescription, onGuildUpdateExplicitContentLevel, onGuildUpdateFeatures, onGuildUpdateIcon, onGuildUpdateLocale, onGuildUpdateMaxMembers, onGuildUpdateMaxPresences, onGuildUpdateMFALevel, onGuildUpdateName, onGuildUpdateNotificationLevel, onGuildUpdateNSFWLevel, onGuildUpdateOwner, onGuildUpdateRulesChannel, onGuildUpdateSplash, onGuildUpdateSystemChannel, onGuildUpdateVanityCode, onGuildUpdateVerificationLevel, onGuildVoiceDeafen, onGuildVoiceGuildDeafen, onGuildVoiceGuildMute, onGuildVoiceJoin, onGuildVoiceLeave, onGuildVoiceMove, onGuildVoiceMute, onGuildVoiceRequestToSpeak, onGuildVoiceSelfDeafen, onGuildVoiceSelfMute, onGuildVoiceStream, onGuildVoiceSuppress, onGuildVoiceUpdate, onGuildVoiceVideo, onHttpRequest, onMessageBulkDelete, onMessageContextInteraction, onMessageDelete, onMessageEmbed, onMessageReactionAdd, onMessageReactionRemove, onMessageReactionRemoveAll, onMessageReactionRemoveEmoji, onMessageUpdate, onModalInteraction, onPermissionOverrideCreate, onPermissionOverrideDelete, onPermissionOverrideUpdate, onRawGateway, onReady, onReconnected, onResumed, onRoleCreate, onRoleDelete, onRoleUpdateColor, onRoleUpdateHoisted, onRoleUpdateIcon, onRoleUpdateMentionable, onRoleUpdateName, onRoleUpdatePermissions, onRoleUpdatePosition, onSelectMenuInteraction, onSelfUpdateAvatar, onSelfUpdateMFA, onSelfUpdateName, onSelfUpdateVerified, onShutdown, onStageInstanceCreate, onStageInstanceDelete, onStageInstanceUpdatePrivacyLevel, onStageInstanceUpdateTopic, onStatusChange, onThreadHidden, onThreadMemberJoin, onThreadMemberLeave, onThreadRevealed, onUnavailableGuildJoined, onUnavailableGuildLeave, onUserActivityEnd, onUserActivityStart, onUserContextInteraction, onUserTyping, onUserUpdateActivities, onUserUpdateActivityOrder, onUserUpdateAvatar, onUserUpdateDiscriminator, onUserUpdateFlags, onUserUpdateName, onUserUpdateOnlineStatusprotected CommandEngine()
ICommandEngine implementations.
It will initialize a SQLite database if the Repository implementation is set as the
IRepository implementation for the Engine (preset by default). You may change it
by using setRepository(IRepository) method.public static void addCommandPackage(String path)
It will also look though sub-packaged.
public static ICommandEngine getInstance()
ICommandEngine that is being used.
By default, CommandEngine implementation will be used.
ICommandEnginepublic static void setInstance(ICommandEngine newCommandConfig)
ICommandEngine. It if highly recommended that to customize the
engine, you extend from the default implementation CommandEngine instead of a raw version.
By default, CommandEngine implementation will be used.
newCommandConfig - custom implementation of ICommandEnginepublic static void includeBuildInUtils()
Help: command to get simple and detailed information about commands.
Ping: Test to see if the bot is reachable.
Language: Set the language used in a guild.
prefix: Set the prefix the bot react to in a guild.
ICommandEngine.addCommand(ICommand) instead.
HelpCommand,
PrefixCommand,
LanguageCommand,
PrefixCommandpublic void logWarn(String message)
ICommandEnginelogWarn in interface ICommandEnginemessage - the message string to be loggedpublic void logDebug(String message)
ICommandEnginelogDebug in interface ICommandEnginemessage - the message string to be loggedpublic void logInfo(String message)
ICommandEnginelogInfo in interface ICommandEnginemessage - the message string to be loggedpublic void logError(String message)
ICommandEnginelogError in interface ICommandEnginemessage - the message string to be loggedpublic ICommandEngine setHelp(String help)
ICommandEnginesetHelp in interface ICommandEnginehelp - command nameHelpCommandpublic ICommand getHelpCommand()
ICommandEnginegetHelpCommand in interface ICommandEnginepublic void loadCommands()
ICommandEngineloadCommands in interface ICommandEnginepublic boolean isReactToMention()
ICommandEngineisReactToMention in interface ICommandEnginepublic ICommandEngine setReactToMention(boolean reactToMention)
ICommandEnginesetReactToMention in interface ICommandEnginereactToMention - True if the bot should react to mention calls.ICommandEngine.getPrefix(MessageReceivedEvent)public boolean isReactToMention(net.dv8tion.jda.api.events.Event event)
ICommandEngineisReactToMention in interface ICommandEngineevent - Discord event that triggered this function call.@Nullable public @Nullable ICommand getCommand(@NotNull @NotNull String name)
ICommandEnginegetCommand in interface ICommandEnginename - command's name.ICommand instance.ICommand@NotNull public @NotNull List<ICommand> getCommandsByPartialMatch(String name)
ICommandEnginegetCommandsByPartialMatch in interface ICommandEnginename - partial command's name.@NotNull public @NotNull List<ICommand> getCommandsByExactMatch(String name)
ICommandEnginegetCommandsByExactMatch in interface ICommandEnginename - expected command's name.@Contract(value=" -> new") @NotNull public final @NotNull @UnmodifiableView List<ICommand> getCommands()
ICommandEngineICommand registered in the Engine.getCommands in interface ICommandEnginepublic ICommandEngine addCommand(@NotNull @NotNull ICommand command) throws DuplicatedNameException, InvalidNameException
ICommandEngineaddCommand in interface ICommandEnginecommand - The command to be registered.DuplicatedNameException - Error if there's another command with the same name or alias registered.InvalidNameException - Error if the command doesn't match the expected name.public ICommandEngine addAlias(@NotNull @NotNull String name, ICommand command) throws DuplicatedNameException, InvalidNameException
ICommandEngineaddAlias in interface ICommandEnginename - alternative name.command - Command to be called.DuplicatedNameException - Thrown when there's already a commando with the same name/alias.InvalidNameException - Thrown when the command's alias uses non-alphanumeric characters.public String getPrefix(@NotNull @NotNull net.dv8tion.jda.api.events.message.MessageReceivedEvent event)
ICommandEnginegetPrefix in interface ICommandEngineevent - Message Received event that triggered this request.public String getPrefix(@NotNull @NotNull net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent event)
ICommandEnginegetPrefix in interface ICommandEngineevent - Slash command that triggered this request.public String getPrefix(@NotNull @NotNull net.dv8tion.jda.api.events.Event event)
ICommandEnginegetPrefix in interface ICommandEngineevent - Event that triggered this request.public String getPrefix()
ICommandEnginegetPrefix in interface ICommandEnginepublic ICommandEngine setPrefix(@NotNull @NotNull String prefix)
ICommandEnginesetPrefix in interface ICommandEngineprefix - prefix string.public ICommandEngine setPrefix(@NotNull @NotNull net.dv8tion.jda.api.entities.Guild guild, @NotNull @NotNull String prefix)
ICommandEnginesetPrefix in interface ICommandEngineguild - Guild object.prefix - prefix String.public Locale getLanguage()
ICommandEnginegetLanguage in interface ICommandEngineMultiLocaleResourceBundle.getSupportedLocale()public ICommandEngine setLanguage(@NotNull @NotNull Locale language)
ICommandEnginesetLanguage in interface ICommandEnginelanguage - Locale to use.MultiLocaleResourceBundle.getSupportedLocale()public Locale getLanguage(@Nullable @Nullable net.dv8tion.jda.api.events.Event event)
ICommandEnginegetLanguage in interface ICommandEngineevent - Discord event that triggered this function call.MultiLocaleResourceBundle.getSupportedLocale()@NotNull public final @NotNull String getString(@NotNull @NotNull String key)
ICommandEnginegetString in interface ICommandEnginekey - String key in resourceBundle.@NotNull public final @NotNull String getString(@NotNull @NotNull String key, @NotNull @NotNull Locale locale)
ICommandEnginegetString in interface ICommandEnginekey - String key in resourceBundle.locale - expected language.@NotNull public final @NotNull String[] getStringArray(@NotNull @NotNull String key)
ICommandEnginegetStringArray in interface ICommandEnginekey - String key in resourceBundle.@NotNull public final @NotNull String[] getStringArray(@NotNull @NotNull String key, @NotNull @NotNull Locale locale)
ICommandEnginegetStringArray in interface ICommandEnginekey - String key in resourceBundle.locale - Expected language.public net.dv8tion.jda.api.JDA getJda()
public ICommandEngine setJda(net.dv8tion.jda.api.JDA jda)
jda - Built JDA object.public IRepository getRepository()
ICommandEnginegetRepository in interface ICommandEnginepublic static void setRepository(IRepository repository)
public final void onMessageReceived(@NotNull
@NotNull net.dv8tion.jda.api.events.message.MessageReceivedEvent event)
onMessageReceived in class net.dv8tion.jda.api.hooks.ListenerAdapterpublic void onSlashCommandInteraction(@NotNull
@NotNull net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent event)
onSlashCommandInteraction in class net.dv8tion.jda.api.hooks.ListenerAdapter@NotNull public static @NotNull net.dv8tion.jda.api.JDA createLight(String token) throws LoginException, IllegalArgumentException
token - The bot token to use.LoginException - If the provided token is invalid.IllegalArgumentException - If the provided token is empty or null.
Or the provided intents/cache configuration is not possible.JDABuilder.build()@NotNull public static @NotNull net.dv8tion.jda.api.JDA createLight(String token, Collection<net.dv8tion.jda.api.requests.GatewayIntent> intents) throws LoginException, IllegalArgumentException
token - The bot token to use.intents - The gateway intents to useLoginException - If the provided token is invalid.IllegalArgumentException - If the provided token is empty or null.
Or the provided intents/cache configuration is not possible.JDABuilder.createLight(String, Collection),
JDABuilder.build()@NotNull public static @NotNull net.dv8tion.jda.api.JDA createLight(String token, net.dv8tion.jda.api.requests.GatewayIntent intent, net.dv8tion.jda.api.requests.GatewayIntent... intents) throws LoginException, IllegalArgumentException
token - The bot token to useintent - The first intent to useintents - The other gateway intents to useLoginException - If the provided token is invalid.IllegalArgumentException - If the provided token is empty or null.
Or the provided intents/cache configuration is not possible.JDABuilder.createLight(String, GatewayIntent, GatewayIntent...),
JDABuilder.build()@NotNull public static @NotNull net.dv8tion.jda.api.JDA create(String token, @Nonnull Collection<net.dv8tion.jda.api.requests.GatewayIntent> intents) throws LoginException, IllegalArgumentException
token - The bot token to useintents - The gateway intents to useLoginException - If the provided token is invalid.IllegalArgumentException - If the provided token is empty or null.
Or the provided intents/cache configuration is not possible.JDABuilder.create(String, GatewayIntent, GatewayIntent...),
JDABuilder.build()@NotNull public static @NotNull net.dv8tion.jda.api.JDA create(String token, net.dv8tion.jda.api.requests.GatewayIntent intent, net.dv8tion.jda.api.requests.GatewayIntent... intents) throws LoginException, IllegalArgumentException
token - The bot token to useintent - The first intent to useintents - The other gateway intents to useLoginException - If the provided token is invalid.IllegalArgumentException - If the provided token is empty or null.
Or the provided intents/cache configuration is not possible.JDABuilder.create(String, GatewayIntent, GatewayIntent...),
JDABuilder.build()@NotNull public static @NotNull net.dv8tion.jda.api.JDA createDefault(String token) throws LoginException, IllegalArgumentException
token - The bot token to use.LoginException - If the provided token is invalid.IllegalArgumentException - If the provided token is empty or null.
Or the provided intents/cache configuration is not possible.JDABuilder.createDefault(String),
JDABuilder.build()@NotNull public static @NotNull net.dv8tion.jda.api.JDA createDefault(String token, Collection<net.dv8tion.jda.api.requests.GatewayIntent> intents) throws LoginException, IllegalArgumentException
token - The bot token to use.intents - The gateway intents to useLoginException - If the provided token is invalid.IllegalArgumentException - If the provided token is empty or null.
Or the provided intents/cache configuration is not possible.JDABuilder.createDefault(String, Collection),
JDABuilder.build()@NotNull public static @NotNull net.dv8tion.jda.api.JDA createDefault(String token, net.dv8tion.jda.api.requests.GatewayIntent intent, net.dv8tion.jda.api.requests.GatewayIntent... intents) throws LoginException, IllegalArgumentException
token - The bot token to useintent - The first intent to useintents - The other gateway intents to useLoginException - If the provided token is invalid.IllegalArgumentException - If the provided token is empty or null.
Or the provided intents/cache configuration is not possible.JDABuilder.createDefault(String, GatewayIntent, GatewayIntent...),
JDABuilder.build()@NotNull
public static @NotNull net.dv8tion.jda.api.JDA create(@NotNull
@NotNull net.dv8tion.jda.api.JDABuilder builder)
throws LoginException,
IllegalArgumentException
This will build the JDA object.
builder - preset JDABuilderLoginException - If the provided token is invalid.IllegalArgumentException - If the provided token is empty or null.
Or the provided intents/cache configuration is not possible.