Class JDACBuilder
This builder is used to build instances of JDACommands.
Please note that values that can be set have a default implementation. These following implementations are based on reflections. If you want to avoid reflections, you have to provide your own implementations for:
descriptor(Descriptor)classFinders(ClassFinder...)instanceProvider(InteractionControllerInstantiator)
In addition to manually configuring this builder, you can also provide implementations of Extension trough Javas service provider interface, which are applied during JDACommands creation.
Values manually defined by this builder will always override loaded and default ones, except for:
which will add to the default and loaded ones.
These implementations of Extension can be additionally configured by adding the according implementation of Extension.Data
by calling extensionData(Extension.Data...). (if supported by the extension)
If any exception while configuration/start of JDA-Commands is thrown, the JDA instance if shutdown per default.
This can be configured by settings shutdownJDA(boolean).
Example
JDACommands jdaCommands = JDACommands.builder(jda, Main.class)
.middleware(Priority.NORMAL, new TestMiddleware())
.globalReplyConfig(new InteractionDefinition.ReplyConfig(false, false, true))
.classFinders(ClassFinder.reflective(Main.class), ClassFinders.explicit(ButtonInteraction.class))
.start();
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enumThe two available filter strategies -
Field Summary
Fields inherited from class com.github.kaktushose.jda.commands.extension.JDACBuilderData
baseClass, classFinders, context, controllerInstantiator, descriptor, embeds, emojiSources, errorMessageFactory, expirationStrategy, extensionData, extensionFilter, globalCommandConfig, globalReplyConfig, guildScopeProvider, loadedExtensions, localizeCommands, localizer, log, middlewares, packages, permissionsProvider, shutdownJDA, typeAdapters, validators -
Method Summary
Modifier and TypeMethodDescriptionadapter(Class<?> source, Class<?> target, TypeAdapter<?, ?> adapter) classFinders(ClassFinder... classFinders) descriptor(Descriptor descriptor) embeds(Consumer<EmbedConfig> consumer) Configuration step for the Embed API of JDA-Commands.emojiSources(EmojiSource... sources) Application emojis loaded fromEmojiSources will be registered upon startup with help ofJDA.createApplicationEmoji(String, Icon).errorMessageFactory(ErrorMessageFactory errorMessageFactory) expirationStrategy(ExpirationStrategy expirationStrategy) extensionData(Extension.Data... data) RegistersExtension.Datathat will be passed to the respectiveExtensions to configure them properly.filterExtensions(JDACBuilder.FilterStrategy strategy, String... classes) Specifies a way to filter found implementations ofExtensionif you have clashing or cycling dependencies for example.globalReplyConfig(InteractionDefinition.ReplyConfig globalReplyConfig) guildScopeProvider(GuildScopeProvider guildScopeProvider) instanceProvider(InteractionControllerInstantiator instanceProvider) localizeCommands(boolean localize) Whether JDA-Commands should use theI18nfeature to localize commands.middleware(Priority priority, Middleware middleware) permissionsProvider(PermissionsProvider permissionsProvider) shutdownJDA(boolean shutdown) Whether the JDA instance should be shutdown if the configuration/start of JDA-Commands fails or ifJDACommands.shutdown()is calledstart()This method applies all found implementations ofExtension, instantiates an instance ofJDACommandsand starts the framework.validator(Class<? extends Annotation> annotation, Validator<?, ?> validator) Methods inherited from class com.github.kaktushose.jda.commands.extension.JDACBuilderData
baseClass, classFinders, context, controllerInstantiator, descriptor, embeds, emojiSources, errorMessageFactory, expirationStrategy, globalCommandConfig, globalReplyConfig, guildScopeProvider, i18n, localizeCommands, localizer, mergedClassFinder, messageResolver, middlewares, packages, permissionsProvider, shutdownJDA, typeAdapters, validators
-
Method Details
-
classFinders
- Parameters:
classFinders- the to be usedClassFinders- API Note:
This method overrides the underlying collection instead of adding to it. If you want to add own
ClassFinders while keeping the default reflective implementation, you have to add it explicitly viatoo.invalid reference
ClassFinder#reflective(Class, String...)
-
emojiSources
Application emojis loaded fromEmojiSources will be registered upon startup with help ofJDA.createApplicationEmoji(String, Icon).- Parameters:
sources- the to be usedEmojiSources- API Note:
This method overrides the underlying collection instead of adding to it. If you want to add own
EmojiSources while keeping the default reflective implementation, you have to add it explicitly viatoo.invalid reference
EmojiSource#reflective(Class, String...)
-
descriptor
- Parameters:
descriptor- theDescriptorto be used
-
embeds
Configuration step for the Embed API of JDA-Commands.
Use the given
EmbedConfigto declare placeholders or data sources. -
localizer
- Parameters:
localizer- TheLocalizerto use
-
instanceProvider
- Parameters:
instanceProvider- the implementation ofInteractionControllerInstantiatorto use
-
expirationStrategy
- Parameters:
expirationStrategy- TheExpirationStrategyto be used
-
middleware
- Parameters:
priority- ThePrioritywith what theMiddlewareshould be registeredmiddleware- The to be registeredMiddleware
-
adapter
- Parameters:
source- The source type that the givenTypeAdaptercan handletarget- The target type that the givenTypeAdaptercan handleadapter- TheTypeAdapterto be registered
-
validator
-
permissionsProvider
- Parameters:
permissionsProvider- ThePermissionsProviderthat should be used
-
errorMessageFactory
- Parameters:
errorMessageFactory- TheErrorMessageFactorythat should be used
-
guildScopeProvider
- Parameters:
guildScopeProvider- TheGuildScopeProviderthat should be used
-
globalReplyConfig
- Parameters:
globalReplyConfig- theInteractionDefinition.ReplyConfigto be used as a global fallback option
-
globalCommandConfig
- Parameters:
config- theCommandDefinition.CommandConfigto be used as a global fallback option
-
extensionData
RegistersExtension.Datathat will be passed to the respectiveExtensions to configure them properly.- Parameters:
data- the instances ofExtension.Datato be used
-
shutdownJDA
Whether the JDA instance should be shutdown if the configuration/start of JDA-Commands fails or ifJDACommands.shutdown()is called- Parameters:
shutdown- whether to shut down the JDA instance, default true
-
localizeCommands
Whether JDA-Commands should use theI18nfeature to localize commands.- Parameters:
localize- whether to localize commands, default true- See Also:
-
filterExtensions
Specifies a way to filter found implementations ofExtensionif you have clashing or cycling dependencies for example.- Parameters:
strategy- the filtering strategy to be used eitherJDACBuilder.FilterStrategy.INCLUDEorJDACBuilder.FilterStrategy.EXCLUDEclasses- the classes to be filtered- API Note:
- This method compares the
fully classified class nameof allExtensionimplementations by usingString.startsWith(String), so it's possible to include/exclude a bunch of classes in the same package by just providing the package name.
-
start
This method applies all found implementations ofExtension, instantiates an instance ofJDACommandsand starts the framework.
-