Skip to content
GitHub

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 & MethodDecorator

Runs 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

NameTypeDescription
...interceptors{ [K in keyof T]: CheckedEntry< T[K], new ( ...args: any[] ) => InterceptorInterface > }

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

Returns

Returns a decorator for a class or a method.

ClassDecorator & MethodDecorator

Throws

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

Examples

TypeScript
@Command('profile', CommandType.SLASH)
@UseInterceptor(TimingInterceptor)
async profile(interaction: ChatInputCommandInteraction) {
  await respond(interaction).send('Your profile.')
}