Piped
type alias in meocord/interface Since 4.1.0
type Piped<T> = T & { readonly [PIPED_BRAND]?: true }Marks a value of a handler's input that a separate @UsePipe produces, so the checks of what a call gives leave
its type to that pipe.
Use it on a key both @Validate and @UsePipe handle, and on a select menu's choice or a typed customId param,
such as {id:int}, that @UsePipe turns into something else; inside the handler it is exactly T. Pipes given
to @Validate itself need no marker.
Examples
import { z } from 'zod'
@Pipe()
class LengthPipe implements PipeInterface<string, number> {
transform(value: string): number {
return value.length
}
}
@Command('count/{text}', CommandType.BUTTON)
@Validate(z.object({ text: z.string() }))
@UsePipe('text', LengthPipe)
async count(interaction: ButtonInteraction, { text }: { text: Piped<number> }) {
await respond(interaction).send(`${text} characters.`)
}See also
- UsePipe
- Validate