|
@@ -19,6 +19,31 @@ You may visit their respective API documentation to find out more. |
|
|
[PreconditionAttribute]: xref:Discord.Commands.PreconditionAttribute |
|
|
[PreconditionAttribute]: xref:Discord.Commands.PreconditionAttribute |
|
|
[ParameterPreconditionAttribute]: xref:Discord.Commands.ParameterPreconditionAttribute |
|
|
[ParameterPreconditionAttribute]: xref:Discord.Commands.ParameterPreconditionAttribute |
|
|
|
|
|
|
|
|
|
|
|
## Using Preconditions |
|
|
|
|
|
|
|
|
|
|
|
To use a precondition, simply apply any valid precondition candidate to |
|
|
|
|
|
a command method signature as an attribute. |
|
|
|
|
|
|
|
|
|
|
|
### Example - Using a Precondition |
|
|
|
|
|
|
|
|
|
|
|
[!code-csharp[Precondition usage](samples/preconditions/precondition_usage.cs)] |
|
|
|
|
|
|
|
|
|
|
|
### ORing Preconditions |
|
|
|
|
|
|
|
|
|
|
|
When writing commands, you may want to allow some of them to be |
|
|
|
|
|
executed when only some of the precondition checks are passed. |
|
|
|
|
|
|
|
|
|
|
|
This is where the [Group] property of a precondition attribute comes in |
|
|
|
|
|
handy. By assigning two or more preconditions to a group, the command |
|
|
|
|
|
system will allow the command to be executed when one of the |
|
|
|
|
|
precondition passes. |
|
|
|
|
|
|
|
|
|
|
|
#### Example - ORing Preconditions |
|
|
|
|
|
|
|
|
|
|
|
[!code-csharp[OR Precondition](samples/preconditions/group_precondition.cs)] |
|
|
|
|
|
|
|
|
|
|
|
[Group]: xref:Discord.Commands.PreconditionAttribute.Group |
|
|
|
|
|
|
|
|
## Bundled Preconditions |
|
|
## Bundled Preconditions |
|
|
|
|
|
|
|
|
@Discord.Commands ships with several bundled Preconditions for you |
|
|
@Discord.Commands ships with several bundled Preconditions for you |
|
@@ -51,7 +76,7 @@ necessary. |
|
|
|
|
|
|
|
|
### Example - Creating a Custom Precondition |
|
|
### Example - Creating a Custom Precondition |
|
|
|
|
|
|
|
|
[!code-csharp[Custom Precondition](samples/require_owner.cs)] |
|
|
|
|
|
|
|
|
[!code-csharp[Custom Precondition](samples/preconditions/require_owner.cs)] |
|
|
|
|
|
|
|
|
[CheckPermissionsAsync]: xref:Discord.Commands.PreconditionAttribute.CheckPermissionsAsync* |
|
|
[CheckPermissionsAsync]: xref:Discord.Commands.PreconditionAttribute.CheckPermissionsAsync* |
|
|
[PreconditionResult.FromSuccess]: xref:Discord.Commands.PreconditionResult.FromSuccess* |
|
|
[PreconditionResult.FromSuccess]: xref:Discord.Commands.PreconditionResult.FromSuccess* |
|
|