Check class
A simple, stateless check for commands.
See AbstractCheck for a description of what a check is.
A Check is a simple check with no state, which validates CommandContexts with a single
callback.
The check succeeds if the callback returns true
and fails if the callback returns false
.
For example, to only allow users with "evrything" in their name to execute a command:
Check check = Check(
(context) => context.user.username.contains('evrything'),
);
commands.addCommand(ChatCommand(
'test',
'A test command',
(IChatContext context) => context.respond(MessageBuilder.content('Hi there!')),
checks: [check],
));
commands.onCommandError.listen((error) {
if (error is CheckFailedException) {
error.context.respond(MessageBuilder.content("Sorry, you can't use that command!"));
}
});
Since some checks are so common, nyxx_commands provides a set of in-built checks that also integrate with the Discord Slash Command Permissions API:
- GuildCheck, for checking if a command was invoked in a specific guild.
You might also be interested in:
- Check.any, Check.deny and Check.all, for modifying the behaviour of checks;
- AbstractCheck, which allows developers to create checks with state.
Constructors
Properties
-
allowsDm
→ FutureOr<
bool> -
Whether this check will allow commands to be executed in DM channels.
final
- hashCode → int
-
The hash code for this object.
no setterinherited
- name → String
-
The name of this check.
finalinherited
-
postCallHooks
→ Iterable<
void Function(CommandContext context)> -
An iterable of callbacks executed after a command is executed.
no setteroverride
-
preCallHooks
→ Iterable<
void Function(CommandContext context)> -
An iterable of callbacks executed before a command is executed but after all the checks for
that command have succeeded.
no setteroverride
-
requiredPermissions
→ FutureOr<
Flags< Permissions> ?> -
The permissions required from members to pass this check.
final
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
check(
CommandContext context) → FutureOr< bool> -
Validate
context
against this check.override -
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited
Static Methods
-
all(
Iterable< AbstractCheck> checks, {String? name}) → AbstractCheck -
Creates a check that succeeds if all of
checks
succeed. -
any(
Iterable< AbstractCheck> checks, [String? name]) → AbstractCheck -
Creates a check that succeeds if any of
checks
succeeds. -
deny(
AbstractCheck check, {String? name}) → AbstractCheck -
Creates a check that succeeds if
check
fails.