PermissionSet
PermissionSet (with a PermissionsBitField subclass, which adds the static Flags and All constants) provides named permission checks against Discord’s 64-bit permission bitfield. Sets are immutable.
Import
Section titled “Import”import { PermissionSet, Permission } from "lunibee";// Alias:import { PermissionsBitField } from "lunibee";import { PermissionSet, Permission } from "lunibee";// Alias:import { PermissionsBitField } from "lunibee";Constructor
Section titled “Constructor”new PermissionSet(value: PermissionResolvable = 0n)new PermissionSet(value = 0n)value is a bitfield (bigint, number or decimal string), a permission name, another set, or an array of these. A negative value throws a RangeError, anything else unparseable a TypeError.
const perms = new PermissionSet(member.permissions.bitfield);const perms = new PermissionSet(member.permissions.bitfield);Properties
Section titled “Properties”| Property | Type | Description |
|---|---|---|
bitfield |
bigint |
The raw bitfield as a BigInt. |
kickMembers, banMembers, administrator, … |
boolean |
One camelCase getter per permission, including setVoiceChannelStatus, pinMessages and bypassSlowmode; true when the bit is set. |
Methods
Section titled “Methods”has(...permissions)
Section titled “has(...permissions)”Returns true only if all of the given permissions are present. Accepts a Permission constant, a bigint, a number, a PermissionSet, an array, or a camelCase/PascalCase permission name string.
if (member.permissions.has(Permission.manageMessages)) { // allowed}
// Also works with string keys:if (member.permissions.has("manageMessages")) { // allowed}if (member.permissions.has(Permission.manageMessages)) { // allowed}
// Also works with string keys:if (member.permissions.has("manageMessages")) { // allowed}any(...permissions)
Section titled “any(...permissions)”Returns true if at least one of the given permissions is present.
if (member.permissions.any(Permission.banMembers, Permission.kickMembers)) { console.log("Can ban or kick.");}if (member.permissions.any(Permission.banMembers, Permission.kickMembers)) { console.log("Can ban or kick.");}For Administrator, use the administrator getter (member.permissions.administrator)
or has(Permission.administrator). has() does not treat Administrator as implying
other permissions.
add(...permissions)
Section titled “add(...permissions)”Returns a new PermissionSet with the given permissions added (immutable).
const updated = perms.add(Permission.sendMessages, Permission.readMessageHistory);const updated = perms.add(Permission.sendMessages, Permission.readMessageHistory);remove(...permissions)
Section titled “remove(...permissions)”Returns a new PermissionSet with the given permissions removed (immutable).
const restricted = perms.remove(Permission.manageMessages);const restricted = perms.remove(Permission.manageMessages);toArray()
Section titled “toArray()”Returns an array of all active permission names.
const permNames = member.permissions.toArray();// → ["viewChannel", "sendMessages", "readMessageHistory", ...]const permNames = member.permissions.toArray();// → ["viewChannel", "sendMessages", "readMessageHistory", ...]equals(other)
Section titled “equals(other)”Whether another PermissionSet or raw bitfield (bigint, number or string) has the same bits.
toString()
Section titled “toString()”Returns the bitfield as a decimal string (useful for API payloads).
const payload = { permissions: member.permissions.toString() };const payload = { permissions: member.permissions.toString() };Permission — Full Reference
Section titled “Permission — Full Reference”All Permission keys use camelCase. A Permissions (PascalCase) alias is also available.
| Key | Bit |
|---|---|
createInstantInvite |
1 << 0 |
kickMembers |
1 << 1 |
banMembers |
1 << 2 |
administrator |
1 << 3 |
manageChannels |
1 << 4 |
manageGuild |
1 << 5 |
addReactions |
1 << 6 |
viewAuditLog |
1 << 7 |
prioritySpeaker |
1 << 8 |
stream |
1 << 9 |
viewChannel |
1 << 10 |
sendMessages |
1 << 11 |
sendTTSMessages |
1 << 12 |
manageMessages |
1 << 13 |
embedLinks |
1 << 14 |
attachFiles |
1 << 15 |
readMessageHistory |
1 << 16 |
mentionEveryone |
1 << 17 |
useExternalEmojis |
1 << 18 |
viewGuildInsights |
1 << 19 |
connect |
1 << 20 |
speak |
1 << 21 |
muteMembers |
1 << 22 |
deafenMembers |
1 << 23 |
moveMembers |
1 << 24 |
useVAD |
1 << 25 |
changeNickname |
1 << 26 |
manageNicknames |
1 << 27 |
manageRoles |
1 << 28 |
manageWebhooks |
1 << 29 |
manageGuildExpressions |
1 << 30 |
useApplicationCommands |
1 << 31 |
requestToSpeak |
1 << 32 |
manageEvents |
1 << 33 |
manageThreads |
1 << 34 |
createPublicThreads |
1 << 35 |
createPrivateThreads |
1 << 36 |
useExternalStickers |
1 << 37 |
sendMessagesInThreads |
1 << 38 |
useEmbeddedActivities |
1 << 39 |
moderateMembers |
1 << 40 |
viewCreatorMonetizationAnalytics |
1 << 41 |
useSoundboard |
1 << 42 |
createGuildExpressions |
1 << 43 |
createEvents |
1 << 44 |
useExternalSounds |
1 << 45 |
sendVoiceMessages |
1 << 46 |
setVoiceChannelStatus |
1 << 48 |
sendPolls |
1 << 49 |
useExternalApps |
1 << 50 |
pinMessages |
1 << 51 |
bypassSlowmode |
1 << 52 |
Examples
Section titled “Examples”Permission gate in a command
import { Permission } from "lunibee";
client.on("interactionCreate", async (interaction) => { if (!interaction.isChatInputCommand() || interaction.commandName !== "ban") return; if (!interaction.member?.permissions.has(Permission.banMembers)) { return interaction.reply({ content: "You need the Ban Members permission.", ephemeral: true }); } // proceed with ban...});import { Permission } from "lunibee";
client.on("interactionCreate", async (interaction) => { if (!interaction.isChatInputCommand() || interaction.commandName !== "ban") return; if (!interaction.member?.permissions.has(Permission.banMembers)) { return interaction.reply({ content: "You need the Ban Members permission.", ephemeral: true }); } // proceed with ban...});Build a permissions embed
const activePerms = member.permissions.toArray();const embed = new CreateEmbed() .setTitle("Your Permissions") .setDescription(activePerms.map(p => `✅ ${p}`).join("\n") || "None");await interaction.reply({ embeds: [embed], ephemeral: true });const activePerms = member.permissions.toArray();const embed = new CreateEmbed() .setTitle("Your Permissions") .setDescription(activePerms.map(p => `✅ ${p}`).join("\n") || "None");await interaction.reply({ embeds: [embed], ephemeral: true });0.2.0 Additions
Section titled “0.2.0 Additions”missing(...permissions)returns the requested permission names the set lacks.- New flags:
setVoiceChannelStatus(bit 48),pinMessages(51),bypassSlowmode(52). computePermissions({ guildId, ownerId, memberId, memberRoleIds, roles, overwrites })resolves effective permissions in Discord’s order (base from@everyoneand the member’s roles, then the@everyoneoverwrite, role overwrites, member overwrite); owners and administrators get every permission. WithtimedOutUntilin the future, the member keeps onlyviewChannelandreadMessageHistory.
const perms = computePermissions({ guildId, ownerId, memberId, memberRoleIds, roles, overwrites });perms.missing("sendMessages", "embedLinks");0.2.1 Additions
Section titled “0.2.1 Additions”Permission names Discord has since renamed still resolve: ManageEmojisAndStickers and ManageEmojis (now ManageGuildExpressions), and UseSlashCommands (now UseApplicationCommands).
GuildMember.permissions is computed from the cached roles for members that did not come with permissions from Discord (see GuildMember).
PermissionFlagsBits
Section titled “PermissionFlagsBits”Discord’s permission bits as bigints: PermissionFlagsBits.BanMembers, PermissionFlagsBits.ManageMessages and so on. It is the same object as Permissions, and every method on this page accepts its values.
member.permissions.has(PermissionFlagsBits.BanMembers);