UseInterceptor
function in meocord/decorator Since 4.1.0
UseInterceptor<const T extends readonly unknown[]>(
...interceptors: {
[K in keyof T]: CheckedEntry<
T[K],
new (...args: any[]) => InterceptorInterface
>
}
): ClassDecorator & MethodDecoratorRuns interceptors around a handler, or around every handler of a controller.
Use it for work that wraps the call: measuring it, logging it, caching its result, or mapping its error.
To decide whether the call runs, use UseGuard; to handle an error only, UseFilter.
Where it runs
- Interceptors — after the guards, around everything up to the handler
Parameters
| Name | Type | Description |
|---|---|---|
...interceptors | {
[K in keyof T]: CheckedEntry<
T[K],
new (
...args: any[]
) => InterceptorInterface
>
} | Interceptor classes, or |
Returns
Returns a decorator for a class or a method.
ClassDecorator & MethodDecoratorThrows
Error when an entry is neither an interceptor class nor
{ provide, params? }, as the decorator applies.
Examples
@Command('profile', CommandType.SLASH)
@UseInterceptor(TimingInterceptor)
async profile(interaction: ChatInputCommandInteraction) {
await respond(interaction).send('Your profile.')
}