discord-bitflag
v1.0.2
Published
A Discord bitfield library
Downloads
308
Readme
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-bitflag
Then 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:
ApplicationFlagsBitField
andApplicationFlags
- Channel Flags:
ChannelFlagsBitField
andChannelFlags
- Guild Member Flags:
GuildMemberFlagsBitField
andGuildMemberFlags
- Intent Flags:
IntentFlagsBitField
andIntentFlags
- Message Flags:
MessageFlagsBitField
andMessageFlags
- Permission Flags:
PermissionsBitField
andPermissionFlags
- User Flags:
UserFlagsBitField
andUserFlags