UseGuard
function in meocord/decorator Since 4.0.0
UseGuard<const T extends readonly unknown[]>(
...entries: {
[K in keyof T]: CheckedEntry<T[K], new (...args: any[]) => GuardInterface>
}
): anyRuns guards before a handler, or before every handler of a controller.
Use it to decide whether a call may run at all: who may use a command, where, or on whose message. To
limit how often a handler runs, use Cooldown; to check its input, Validate.
Where it runs
- Guards — after the global guards from
@MeoCord({ guards }), a controller's before a method's
Parameters
| Name | Type | Since | Description |
|---|---|---|---|
...entries | {
[K in keyof T]: CheckedEntry<
T[K],
new (...args: any[]) => GuardInterface
>
} | 4.1.0 | Guard classes, or |
Returns
anyThrows
Error when an entry is neither a guard class nor
{ provide, params? }, as the decorator applies.
Examples
@Command('trade', CommandType.SLASH)
@UseGuard(StaffGuard, { provide: ChannelGuard, params: { channelIds: ['123456789012345678'] } })
async trade(interaction: ChatInputCommandInteraction) {
await respond(interaction).send('Trade opened.')
}