TextCommandFilter

@InterfacedService(acceptMultiple = true)
interface TextCommandFilter<T : Any> : Filter(source)

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

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

T

Type of the error object handled by TextCommandRejectionHandler

See also

Properties

Link copied to clipboard

Description of the filter, used for logging purposes (like when a filter rejects a command).

Link copied to clipboard
open val global: Boolean

Whether this filter is global or command-specific.

Functions

Link copied to clipboard
Link copied to clipboard
open fun check(event: MessageReceivedEvent, commandVariation: TextCommandVariation, args: String): T?

Returns null if this filter should allow the command to run, or returns your own object if it can't.

Link copied to clipboard
open suspend fun checkSuspend(event: MessageReceivedEvent, commandVariation: TextCommandVariation, args: String): T?

Returns null if this filter should allow the command to run, or returns your own object if it can't.

Link copied to clipboard