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 in the configuration block.
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
object EnumResolvers {
// Resolver for DAYS/HOURS/MINUTES, where the displayed name is given by 'Resolvers.Enum#toHumanName'
@Resolver
fun timeUnitResolver() = enumResolver<TimeUnit>(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 a human friendly name for the enum value, defaults to toHumanName
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 in the configuration block.
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
object EnumResolvers {
// Resolver for DAYS/HOURS/MINUTES (and SECONDS in the test guild), where the displayed name is given by 'Resolvers.Enum#toHumanName'
@Resolver
fun timeUnitResolver() = enumResolver<TimeUnit> { guild ->
if (guild.isTestGuild()) {
enumSetOf(TimeUnit.DAYS, TimeUnit.HOURS, TimeUnit.MINUTES, TimeUnit.SECONDS)
} else {
enumSetOf(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
Retrieves a human friendly name for the enum value, defaults to toHumanName