enumResolver

@CheckReturnValue
fun <E : Enum<E>> enumResolver(e: Class<E>, guildValuesSupplier: EnumValuesSupplier<E>): EnumResolverBuilder<E>(source)

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:

  1. MY_ENUM_VALUE (Raw enum name)

  2. My enum value (Choice name displayed on Discord)

  3. my_enum_value (Choice name in your localization file)

Parameters

e

The enum type

guildValuesSupplier

Retrieves the values used for slash command choices, for each Guild

See also


@CheckReturnValue
fun <E : Enum<E>> enumResolver(e: Class<E>, values: Collection<E> = EnumSet.allOf(e)): EnumResolverBuilder<E>(source)

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:

  1. MY_ENUM_VALUE (Raw enum name)

  2. My enum value (Choice name displayed on Discord)

  3. my_enum_value (Choice name in your localization file)

Parameters

e

The enum type

values

The values used for slash command choices

See also