1.0.2 • Published 1 year ago
discord-bitflag v1.0.2
discord-bitflag
A JavaScript wrapper for Discord bitflags. You can easily modify Permissions, Intents, User flags, Channel Flags, and more with this library.
Usage
Install the library by running
npm i discord-bitflagThen import and use it in your code like this:
import { PermissionFlags, PermissionsBitField } from "discord-bitflag";
const response = await fetch(DISCORD_API, { ...options });
const permissions = new PermissionsBitField(response.permissions);
if (permissions.has(PermissionFlags.BanMembers)) {
console.log("This user can ban members!");
}
if (permissions.has(PermissionsBitField.ALL)) {
console.log("This user has all permissions!");
}
if (permissions.hasWithoutAdmin(PermissionsBitField.ALL)) {
console.log("This user REALLY has all permissions!");
}Permissions API
The Permissions BitField class checks for the Admin permission by default when you check a permission via the .has() method. If you would like to check to see if a permission is explicitly enabled without checking Admin, you can use the .hasWithoutAdmin() method instead.
Bit Fields
Each bit field class extends the BitField class from bitflag-js.
- Application Flags:
ApplicationFlagsBitFieldandApplicationFlags - Channel Flags:
ChannelFlagsBitFieldandChannelFlags - Guild Member Flags:
GuildMemberFlagsBitFieldandGuildMemberFlags - Intent Flags:
IntentFlagsBitFieldandIntentFlags - Message Flags:
MessageFlagsBitFieldandMessageFlags - Permission Flags:
PermissionsBitFieldandPermissionFlags - User Flags:
UserFlagsBitFieldandUserFlags