Controller
function in meocord/decorator Since 4.0.0
Controller(
options?: ControllerOptions,
): (
target: abstract new (...args: any[]) => unknown,
propertyKey?: string | symbol,
) => voidMarks 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
| Name | Type | Default | Since | Description |
|---|---|---|---|---|
options? | ControllerOptions | 4.1.0 | Whether the handlers it declares take the stages of the classes it extends. | |
options.inheritStages? | boolean | true | 4.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. |
options.inheritedRoutes? | 'keep' | 'replace' | 'keep'`; the next major version (5.0) replaces them by default | 4.2.0 | What a handler this class re-decorates answers of the routes its base classes declare for it. |
Returns
Returns a property decorator.
(
target: abstract new (...args: any[]) => unknown,
propertyKey?: string | symbol,
) => voidExamples
@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)] })
}
}