# defineGate

`function` in `core` · v0.10.0

<https://seedcord.org/docs/packages/core/0.10.0/functions/define-gate>

Builds a [`Gate`](/docs/packages/core/0.10.0/interfaces/gate) from a check. The check refuses by throwing a Notice or a Silence and passes
by returning. The required context is inferred from `ctx`, so annotate it as narrowly as the fields
the check reads. No annotation defaults to [`GateContextBase`](/docs/packages/core/0.10.0/interfaces/gate-context-base), an agnostic gate that fits every
handler.

```ts
defineGate<Name, Ctx>(
    name: Name,
    fn: (ctx: Ctx) => void | Promise<void>
): Gate<Ctx, Name>
```

Builds a [`Gate`](/docs/packages/core/0.10.0/interfaces/gate) from a check. The check refuses by throwing a Notice or a Silence and passes
by returning. The required context is inferred from `ctx`, so annotate it as narrowly as the fields
the check reads. No annotation defaults to [`GateContextBase`](/docs/packages/core/0.10.0/interfaces/gate-context-base), an agnostic gate that fits every
handler.

Parameters.

- `name` `Name` — The gate's name, used in mismatch errors.
- `fn` `(ctx: Ctx) => void | Promise<void>` — The check, which refuses by throwing a Notice or a Silence and passes by returning.

Returns `Gate<Ctx, Name>`.
