GuardDeniedError
class in meocord/common Since 4.1.0
class GuardDeniedError extends ErrorThrown by a guard to deny a call and tell the user why.
Use it where returning false, which denies silently, would leave the user guessing. The built-in fallback shows
the message privately to the user who made an interaction, and as a reply to a message command; a listener's or a
reaction's denial is only logged. A filter can catch it to answer otherwise.
Examples
@Guard()
export class OwnerGuard implements GuardInterface {
canActivate(interaction: ButtonInteraction, { ownerId }: { ownerId: string }): boolean {
if (interaction.user.id !== ownerId) throw new GuardDeniedError('Only the owner can use this.')
return true
}
}Members
constructor
new GuardDeniedError(message: string)Parameters
| Name | Type | Description |
|---|---|---|
message | string | What the user is told. |
See also
- Guard
- UserError