enum Resolver
Creates an enum resolver for slash commands, as well as component data and timeout data.
Text command support
To add support for text command options, you have to use EnumResolverBuilder.withTextSupport.
Using choices
You have to enable SlashOption.usePredefinedChoices for the choices to appear on your slash command option.
Registration
The created resolver needs to be registered as a service factory, with @Resolver, for example:
@BConfiguration
public class EnumResolvers {
// Resolver for DAYS/HOURS/MINUTES (and SECONDS in the test guild), where the displayed name is given by 'Resolvers#toHumanName'
@Resolver
public ParameterResolver<?, ?> timeUnitResolver() {
return Resolvers.enumResolver(
TimeUnit.class,
guild -> Utils.isTestGuild(guild)
? EnumSet.of(TimeUnit.DAYS, TimeUnit.HOURS, TimeUnit.MINUTES, TimeUnit.SECONDS)
: EnumSet.of(TimeUnit.DAYS, TimeUnit.HOURS, TimeUnit.MINUTES)
);
}
...other resolvers...
}
Localization
The choices are localized automatically by using the bundles defined by BApplicationConfigBuilder.addLocalizations, using a path similar to my.command.path.options.my_option.choices.choice_name.name, as required by LocalizationFunction.
The choice name is produced by the name function, and is then lowercase with spaces modified to underscore by LocalizationFunction.
For example, using the default name function:
MY_ENUM_VALUE
(Raw enum name)My enum value
(Choice name displayed on Discord)my_enum_value
(Choice name in your localization file)
Parameters
The enum type
Retrieves the values used for slash command choices, for each Guild
See also
Creates an enum resolver for slash commands, as well as component data and timeout data.
Text command support
To add support for text command options, you have to use EnumResolverBuilder.withTextSupport.
Using choices
You have to enable SlashOption.usePredefinedChoices for the choices to appear on your slash command option.
Registration
The created resolver needs to be registered as a service factory, with @Resolver, for example:
@BConfiguration
public class EnumResolvers {
// Resolver for DAYS/HOURS/MINUTES, where the displayed name is given by 'Resolvers#toHumanName'
@Resolver
public ParameterResolver<?, ?> timeUnitResolver() {
return Resolvers.enumResolver(TimeUnit.class, EnumSet.of(TimeUnit.DAYS, TimeUnit.HOURS, TimeUnit.MINUTES)).build();
}
...other resolvers...
}
Localization
The choices are localized automatically by using the bundles defined by BApplicationConfigBuilder.addLocalizations, using a path similar to my.command.path.options.my_option.choices.choice_name.name, as required by LocalizationFunction.
The choice name is produced by the name function, and is then lowercase with spaces modified to underscore by LocalizationFunction.
For example, using the default name function:
MY_ENUM_VALUE
(Raw enum name)My enum value
(Choice name displayed on Discord)my_enum_value
(Choice name in your localization file)
Parameters
The enum type
The values used for slash command choices