@@ -5,7 +5,7 @@ title: Preconditions
# Preconditions
# Preconditions
Precondition serve as a permissions system for your Commands. Keep in
Preconditions serve as a permissions system for your Commands. Keep in
mind, however, that they are not limited to _just_ permissions and can
mind, however, that they are not limited to _just_ permissions and can
be as complex as you want them to be.
be as complex as you want them to be.
@@ -21,8 +21,8 @@ You may visit their respective API documentation to find out more.
## Bundled Preconditions
## Bundled Preconditions
@Discord.Commands ship with several bundled Preconditions; you may
view their usages on their respective API pages .
@Discord.Commands ships with several bundled Preconditions for you
to use .
* @Discord.Commands.RequireContextAttribute
* @Discord.Commands.RequireContextAttribute
* @Discord.Commands.RequireOwnerAttribute
* @Discord.Commands.RequireOwnerAttribute
@@ -39,13 +39,18 @@ depending on your use.
In order for your Precondition to function, you will need to override
In order for your Precondition to function, you will need to override
the [CheckPermissionsAsync] method.
the [CheckPermissionsAsync] method.
Your IDE should provide an option to fill this in for you.
If the context meets the required parameters, return
If the context meets the required parameters, return
[PreconditionResult.FromSuccess], otherwise return
[PreconditionResult.FromSuccess], otherwise return
[PreconditionResult.FromError] and include an error message if
[PreconditionResult.FromError] and include an error message if
necessary.
necessary.
> [!NOTE]
> Visual Studio can help you implement missing members
> from the abstract class by using the "Implement Abstract Class"
> IntelliSense hint.
### Example - Creating a Custom Precondition
[!code-csharp[Custom Precondition](samples/require_owner.cs)]
[!code-csharp[Custom Precondition](samples/require_owner.cs)]
[CheckPermissionsAsync]: xref:Discord.Commands.PreconditionAttribute.CheckPermissionsAsync*
[CheckPermissionsAsync]: xref:Discord.Commands.PreconditionAttribute.CheckPermissionsAsync*