Skip to content
GitHub

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>>,
) => void

Runs 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

NameTypeDescription
keyK

The input key: a command option, customId param, modal field or message param name.

...pipesPipes & { [I in keyof Pipes]: CheckedEntry< Pipes[I], new (...args: any[]) => PipeInterface > }

Pipe classes, or { provide, params? } to give one use its params, which the pipe reads with context.getParams().

Returns

Returns a method decorator.

<M extends Handler>(
  target: object,
  propertyKey: string,
  _descriptor: TypedPropertyDescriptor<M> &
    AcceptsPiped<ParamsOf<M>, K, LastPipeOutput<Pipes>>,
) => void

Throws

  • Error when an entry is neither a pipe class nor { provide, params? }, as the decorator applies.

Examples

TypeScript
@Command('say', CommandType.SLASH)
@UsePipe('text', TrimPipe)
async say(interaction: ChatInputCommandInteraction, { text }: { text: string }) {
  await respond(interaction).send(text)
}