Skip to content
Functioncorev0.14.0

RequirePermissions

Requires the caller to hold every permission in scope. Refuses outside a guild first, then when the member's permissions are unavailable, then when a permission is missing. The Administrator bit passes any scope.

The default 'channel' scope reads the effective channel set in the payload, what Discord enforces in the invoked channel. The 'guild' scope reads the base set from roles and fits a gateway handler only because it requires a GuildPermissionsContext.

See also:the @Gated decorator from your transport package

RequirePermissions(
    scope: PermissionScope,
    options: RequirePermissionsOptions & { in: "guild" }
): Gate<GuildPermissionsContext, "RequirePermissions">
import { PermissionFlagsBits } from 'discord-api-types/v10';

\@Gated(RequirePermissions([PermissionFlagsBits.BanMembers]))
\@SlashRoute('ban')
class BanHandler extends SlashHandler<'ban'> {
    async execute() {
        // ...
    }
}
// the base set from roles, on a gateway handler
RequirePermissions([PermissionFlagsBits.BanMembers], { in: 'guild' });

scope

The permission flag bits the caller must all hold.

options

options: RequirePermissionsOptions & { in: 'guild'; }

Pick the scope with in. Replace a refusal with a Notice class as notInGuild, unresolved, or missing.