UsePipe
function in meocord/decorator Since 4.1.0
UsePipe<
K extends string,
const Pipes extends readonly [PipeEntryOf, ...PipeEntryOf[]],
>(
key: K,
...pipes: Pipes & {
[I in keyof Pipes]: CheckedEntry<
Pipes[I],
new (...args: any[]) => PipeInterface
>
}
): <M extends Handler>(
target: object,
propertyKey: string,
_descriptor: TypedPropertyDescriptor<M> &
AcceptsPiped<ParamsOf<M>, K, LastPipeOutput<Pipes>>,
) => voidRuns pipes on one value of a handler's input, to turn it into what the handler works with.
Use it to trim, parse or look up a single option, customId param or field, such as an account ID into the
account. To check the whole input first, use Validate; its own pipes option does the same for the
schema's output.
Where it runs
- Pipes — after validation
Parameters
| Name | Type | Description |
|---|---|---|
key | K | The input key: a command option, customId param, modal field or message param name. |
...pipes | Pipes & {
[I in keyof Pipes]: CheckedEntry<
Pipes[I],
new (...args: any[]) => PipeInterface
>
} | Pipe classes, or |
Returns
Returns a method decorator.
<M extends Handler>(
target: object,
propertyKey: string,
_descriptor: TypedPropertyDescriptor<M> &
AcceptsPiped<ParamsOf<M>, K, LastPipeOutput<Pipes>>,
) => voidThrows
Error when an entry is neither a pipe class nor
{ provide, params? }, as the decorator applies.
Examples
@Command('say', CommandType.SLASH)
@UsePipe('text', TrimPipe)
async say(interaction: ChatInputCommandInteraction, { text }: { text: string }) {
await respond(interaction).send(text)
}