any static method
- Iterable<
AbstractCheck> checks, - [String? name]
Creates a check that succeeds if any of checks
succeeds.
When this check is queried, each of checks
is queried and if any are successful then this
check is successful. If all of checks
fail, then this check is failed.
Sometimes, developers might want to apply a check to all commands of a certain type. Instead of adding a check on each command of that type, nyxx_commands provides checks that will succeed when the context being checked is of a certain type:
- InteractionCommandCheck, to check if the context originated from an interaction;
- ChatCommandCheck, to check if the command being invoked is a chat command;
- MessageChatCommandCheck, to check if the context originated from a text message (only applies to chat commands);
- InteractionChatCommandCheck, to check if the command being executed is a chat command and that the context originated from an interaction;
- MessageCommandCheck, to check if the command being executed is a Message Command;
- UserCommandCheck, to check if the command being executed is a User Command.
For example, to only apply a check only to commands invoked from a message command:
commands.check(Check.any([
InteractionCommandCheck(),
Check((context) => context.user.username.contains('evrything')),
]));
commands.addCommand(ChatCommand(
'test',
'A test command',
(IChatContext context) => context.respond(MessageBuilder.content('Hi there!')),
));
commands.onCommandError.listen((error) {
if (error is CheckFailedException) {
error.context.respond(MessageBuilder.content("Sorry, you can't use that command!"));
}
});
Implementation
static AbstractCheck any(Iterable<AbstractCheck> checks, [String? name]) =>
_AnyCheck(checks, name);