> For the complete documentation index, see [llms.txt](https://go-adam.gitbook.io/adam/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://go-adam.gitbook.io/adam/restrictions/custom-restrictions.md).

# Creating Custom Restrictions

Package `restriction` provides some defaults, but you can also create your own. Before you do that there are a few things to keep in mind.

### What Errors to Return

The `plugin` package provides the `RestrictionError` type. intended to be used by restrictions. As mentioned in [Error Types](/adam/errors/error-types.md), there are two types of `RestrictionError`s, fatal and non-fatal ones.

A fatal `RestrictionError` should be returned, if the user has no way of influencing the occurrence of the error by themselves. Simply ask yourself, "If this restriction fails, should the help command still list this command for the user?". If so, use a non-fatal `RestrictionError`.

If an internal error occurs during the execution of a restriction, it of course should be returned as-is.

### Performing Time-Consuming Tasks

Restrictions should never perform time-consuming tasks, without ensuring that the results are cached. This is simply because help commands may check the restrictions of every command to determine whether the user may access them.

Therefore, it is recommended to either perform expensive tasks once and store the result using `plugin.Context.Set`, or access this kind of data through a cache-layer to prevent reoccurring delays.

The getters getting Discord data found in the `plugin.Context` are cached for the duration of the command's execution regardless of the state's cache settings, and are therefore safe to access.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://go-adam.gitbook.io/adam/restrictions/custom-restrictions.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
