> ## Documentation Index
> Fetch the complete documentation index at: https://stars-components.js.org/llms.txt
> Use this file to discover all available pages before exploring further.

# Function: createFunctionPrecondition()

> **createFunctionPrecondition**(`precondition`, `fallback?`): `MethodDecorator`

Defined in: [packages/http-framework/src/lib/decorators/utils.ts:72](https://github.com/wolfstar-project/stars-components/blob/5aefd164bc5fc41e5a35d3abf908c288163dd354/packages/http-framework/src/lib/decorators/utils.ts#L72)

Utility to make a method decorator with lighter syntax and inferred types.

## Parameters

### precondition

(...`args`) => `boolean` | `Promise`\<`boolean`>

The predicate to run before the decorated method. It receives the same arguments as the method
and is called with the same `this`.

### fallback?

(...`args`) => `unknown`

The fallback to run when the precondition is not met. Defaults to a no-op returning `undefined`.

## Returns

`MethodDecorator`

The decorator.

## Remarks

The decorated method is replaced by an `async` one, so it always returns a `Promise`, even when both the
precondition and the original method are synchronous.

## Example

```typescript theme={"system"}
import { Command, RegisterCommand, createFunctionPrecondition } from '@wolfstar/http-framework';

const RequiresOwner = createFunctionPrecondition(
	(interaction: Command.ChatInputInteraction) => interaction.user.id === process.env.OWNER_ID,
	(interaction: Command.ChatInputInteraction) => interaction.reply({ content: 'Owner only.' })
);
```
