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:
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 and
which will override the default but add to the 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 is shutdown per default.
This can be configured by settings shutdownJDA(boolean).
Example
JDACommands jdaCommands = JDACommands.builder(jda)
.middleware(Priority.NORMAL, new TestMiddleware())
.globalReplyConfig(new InteractionDefinition.ReplyConfig(false, false, true))
.classFinders(ClassFinder.reflective(Main.class), ClassFinders.explicit(ButtonInteraction.class))
.start();
- See Also:
-
Method Summary
Modifier and TypeMethodDescription<S,T> JDACBuilder adapter(Class<S> source, Class<T> target, TypeAdapter<S, T> adapter) classFinders(ClassFinder... classFinders) descriptor(Descriptor descriptor) embeds(Consumer<EmbedConfig> consumer) Configuration step for the Embed API of JDA-Commands.emojiSource(EmojiSource... sources) Application emojis loaded fromEmojiSources will be registered upon startup with help ofJDA.createApplicationEmoji(String, Icon).errorMessageFactory(ErrorMessageFactory errorMessageFactory) expirationStrategy(ExpirationStrategy strategy) extensionData(Extension.Data... data) RegistersExtension.Datathat will be passed to the respectiveExtensions to configure them properly.filterExtensions(ExtensionFilter.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) instantiator(Instantiator instantiator) localizeCommands(boolean localize) Whether JDA-Commands should use theI18nfeature to localize commands.middleware(Priority priority, Middleware middleware) Some default implementations likeClassFinder.reflective(String...)will scan the classpath to find classes and resource.permissionsProvider(PermissionsProvider permissionsProvider) <T> JDACBuildersetProperty(JDACProperty<T> property, Function<JDACIntrospection, T> supplier) Allows the dynamic configuration of JDA-Commands by settingJDACPropertys directly.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.final JDACBuilderstringResolver(Resolver<String>... resolvers) Adds aResolverin the resolution chain for strings provided by the user in annotations, components etc.validator(Class<? extends Annotation> annotation, Validator<?, ?> validator)
-
Method Details
-
packages
Some default implementations likeClassFinder.reflective(String...)will scan the classpath to find classes and resource. This config option allows you to restrict the to be scanned packages.- Parameters:
packages- the packages to scan recursively
-
classFinders
- Parameters:
classFinders- the to be usedClassFinders- API Note:
- This method overrides the default/fallback value but adds to the loaded ones.
If you want to add own
ClassFinders while keeping the default reflective implementation, you have to add it explicitly viaClassFinder.reflective(String...)too.
-
emojiSource
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 default/fallback value but adds to the loaded ones.
If you want to add own
EmojiSources while keeping the default reflective implementation, you have to add it explicitly viaEmojiSource.reflective(String...)too.
-
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
-
instantiator
- Parameters:
instantiator- the implementation ofInstantiatorto use
-
expirationStrategy
- Parameters:
strategy- 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 eitherExtensionFilter.FilterStrategy.INCLUDEorExtensionFilter.FilterStrategy.EXCLUDEclasses- the classes to be filtered- See Also:
- 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 extensions sharing the same base package by just providing the package name.
-
stringResolver
Adds a
Resolverin the resolution chain for strings provided by the user in annotations, components etc.All
Resolvers are accumulated byMessageResolver. This method adds to the default resolvers like localization, placeholders and emojis- Parameters:
resolvers- theResolvers to add- See Also:
-
setProperty
public <T> JDACBuilder setProperty(JDACProperty<T> property, Function<JDACIntrospection, T> supplier) Allows the dynamic configuration of JDA-Commands by settingJDACPropertys directly.- Parameters:
property- theJDACPropertyto be setsupplier- the function providing the custom value for it (PropertyProviderSkeleton.supplier())- See Also:
- Implementation Note:
- the values will be added as
JDACPropertyProviders with priority set toInteger.MAX_VALUElike they were set by any other method of this class.
-
start
This method applies all found implementations ofExtension, instantiates an instance ofJDACommandsand starts the framework.
-