Skip to content
GitHub

Controller

function in meocord/decorator Since 4.0.0

Controller(
  options?: ControllerOptions,
): (
  target: abstract new (...args: any[]) => unknown,
  propertyKey?: string | symbol,
) => void

Marks a class as a controller, whose methods handle commands, components, messages, reactions or events.

Use it on every class of handlers, and list the class in @MeoCord({ controllers }). Logic the handlers share, such as database access, belongs in a service it injects.

Parameters

NameTypeDefaultSinceDescription
options?ControllerOptions4.1.0

Whether the handlers it declares take the stages of the classes it extends.

options.inheritStages?booleantrue4.1.0

Whether the class-level guards, interceptors, filters and cooldowns of the classes this one extends also apply to the handlers it declares itself. false limits those handlers to this class's own class and method stages; handlers it inherits keep their base's stages either way.

options.inheritedRoutes?'keep' | 'replace''keep'`; the next major version (5.0) replaces them by default4.2.0

What a handler this class re-decorates answers of the routes its base classes declare for it. 'keep' answers them as well as its own; 'replace' answers only the routes this class declares for it, of every kind: commands, component patterns, message patterns, reactions and autocompletes. A command no handler answers any more is not registered. A method overridden without decorators keeps every route it inherits either way.

Returns

Returns a property decorator.

(
  target: abstract new (...args: any[]) => unknown,
  propertyKey?: string | symbol,
) => void

Examples

TypeScript
@Controller()
export class ProfileSlashController {
  constructor(private readonly profiles: ProfileService) {}

  @Command('profile', CommandType.SLASH)
  async profile(interaction: ChatInputCommandInteraction) {
    await respond(interaction).send({ embeds: [await this.profiles.render(interaction.user.id)] })
  }
}