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.

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)] })
  }
}