Functioncorev0.14.0
assertPermissions
Refuses when the subject is missing a permission in scope, or with inverse when it holds one.
The Administrator bit passes any scope, and with inverse it reports every bit in scope.
The caller computes permissions, gateway off a discord.js role, member, or channel, and HTTP off the
bitfield in the interaction payload.
Throws:
A
Noticewhen the check refuses. It lists the missing or present permissions.
assertPermissions(
{ subject, permissions, scope, inverse, notice },
input: PermissionAssertion
): voidimport { assertPermissions } from '@seedcord/core';
import { PermissionFlagsBits } from 'discord-api-types/v10';
// gateway, the bits come off a discord.js member
assertPermissions({
subject: `<@${member.id}>`,
permissions: member.permissions.bitfield,
scope: [PermissionFlagsBits.BanMembers]
});// HTTP, the payload carries the member's bits as a string
assertPermissions({
subject: `<@${this.event.member.user.id}>`,
permissions: BigInt(this.event.member.permissions),
scope: [PermissionFlagsBits.ManageMessages]
});// inverse, refuse a role that carries Administrator
assertPermissions({
subject: `<@&${role.id}>`,
permissions: role.permissions.bitfield,
scope: [PermissionFlagsBits.Administrator],
inverse: true
});import { Notice } from '@seedcord/core';
class CannotBan extends Notice {
public constructor(
private readonly subject: string | null,
private readonly missing: readonly string[]
) {
super('You cannot ban here.');
}
public render(): ReplyResponse {
return { components: [new BanDenied(this.subject, this.missing).component] };
}
}
assertPermissions({
subject: `<@${member.id}>`,
permissions: member.permissions.bitfield,
scope: [PermissionFlagsBits.BanMembers],
notice: CannotBan
});{ subject, permissions, scope, inverse, notice }
{ subject, permissions, scope, inverse, notice }input
input: PermissionAssertion