# defineGate

`function` in `seedcord` · v0.15.0

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

Builds a [`Gate`](/packages/seedcord/0.15.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`](/packages/seedcord/0.15.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`](/packages/seedcord/0.15.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`](/packages/seedcord/0.15.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>`.
