Skip to content
GitHub

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>
  }
): any

Runs 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

NameTypeSinceDescription
...entries{ [K in keyof T]: CheckedEntry< T[K], new (...args: any[]) => GuardInterface > }4.1.0

Guard classes, or { provide, params? } to give one use of a guard its params.

Returns

any

Throws

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

Examples

TypeScript
@Command('trade', CommandType.SLASH)
@UseGuard(StaffGuard, { provide: ChannelGuard, params: { channelIds: ['123456789012345678'] } })
async trade(interaction: ChatInputCommandInteraction) {
  await respond(interaction).send('Trade opened.')
}