Prechecks
Learn how to use prechecks to add additional validation and checks before a command runs.
Prechecks are a powerful feature in Carbon that allow you to add additional validation and checks before a command is executed. This can be useful for implementing features like cooldowns, permission checks, or any other validation that needs to happen before the main command logic runs.
How Prechecks Work
Prechecks are implemented by overriding the preCheck
method in your command class. This method is called before the main run
method of your command. If the precheck returns anything other than true
, the command will not execute.
Here's a basic example of a precheck:
Common Use Cases
Cooldowns
You can implement cooldowns using prechecks to prevent users from spamming commands:
Permission Checks
You can use prechecks to verify if a user has the necessary permissions to use a command:
Maintenance Mode
You can implement a maintenance mode that prevents commands from being used:
Last updated on
Replying vs Defering vs Achnowledging
Understand the different ways to respond to Discord interactions, including replying, deferring, and acknowledging, and learn when to use each method.
Partial Structures
Learn about partial structures in the Discord API and how to handle them in Carbon, including retrieving full data and checking for undefined properties.