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. OwnerGuard denies this way.
Examples
@Guard({ types: ['interaction'] })
export class ModeratorGuard implements GuardInterface {
canActivate(interaction: ChatInputCommandInteraction): boolean {
if (!interaction.memberPermissions?.has(PermissionFlagsBits.ManageMessages)) throw new GuardDeniedError('Only moderators can use this.')
return true
}
}Members
constructor
new GuardDeniedError(message: string)Parameters
| Name | Type |
|---|---|
message | string |
What the user is told. | |
See also
- Guard
- OwnerGuard
- UserError