Application Command Filter
Prevents application command execution by returning an error object to the command executor.
Filters run when an application command is about to be executed, i.e., after the permissions/rate limits... were checked.
When the final filter returns an error object of type T, it will then be passed to the ApplicationCommandRejectionHandler.
Combining filters
Filters can be combined with and
/or
(static methods for Java users).
Requirements
Register your instance as a service with @BService. This is not required if you pass the instance directly to the command builder.
Have exactly one instance of ApplicationCommandRejectionHandler.
Implement either check (Java) or checkSuspend (Kotlin).
(Optional) Set your filter as a command-specific filter by disabling global.
Execution order
The execution order of global filters is determined by the priority of the service, while command-specific filters use the insertion order.
Example - Accepting commands only in a single channel
@BService
class MyApplicationCommandFilter : ApplicationCommandFilter<String> {
override suspend fun checkSuspend(event: GenericCommandInteractionEvent, commandInfo: ApplicationCommandInfo): String? {
if (event.guildChannel.idLong != 722891685755093076) {
return "Can only run commands in <#722891685755093076>"
}
return null
}
}
@BService
public class MyApplicationCommandFilter implements ApplicationCommandFilter<String> {
@Nullable
@Override
public String check(@NotNull GenericCommandInteractionEvent event, @NotNull ApplicationCommandInfo commandInfo) {
if (channel.getIdLong() != 722891685755093076L) {
return "Can only run commands in <#722891685755093076>";
}
return null;
}
}
Parameters
Type of the error object handled by ApplicationCommandRejectionHandler
See also
@InterfacedService
Properties
Functions
Returns null
if this filter should allow the command to run, or returns your own object if it can't.
Returns null
if this filter should allow the command to run, or returns your own object if it can't.