Text Command Filter
Prevents text command execution by returning an error object to the command executor.
Filters run when a command variation 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 TextCommandRejectionHandler.
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 TextCommandRejectionHandler.
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 MyTextCommandFilter : TextCommandFilter<String> {
override suspend fun checkSuspend(event: MessageReceivedEvent, commandVariation: TextCommandVariation, args: String): String? {
if (event.guildChannel.idLong != 722891685755093076) {
return "Can only run commands in <#722891685755093076>"
}
return null
}
}
@BService
public class MyTextCommandFilter implements TextCommandFilter<String> {
@Nullable
@Override
public String check(@NotNull MessageReceivedEvent event, @NotNull TextCommandVariation commandVariation, @NotNull String args) {
if (channel.getIdLong() != 722891685755093076L) {
return "Can only run commands in <#722891685755093076>";
}
return null;
}
}
Parameters
Type of the error object handled by TextCommandRejectionHandler
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.