How do i handle permission bits when using REST

const allowValue = channel.permission_overwrites?.find((p) => p.id === membersRole.id)?.allow === '2048'
const denyValue = channel.permission_overwrites?.find((p) => p.id === membersRole.id)?.deny === '2048'
const allowValue = channel.permission_overwrites?.find((p) => p.id === membersRole.id)?.allow === '2048'
const denyValue = channel.permission_overwrites?.find((p) => p.id === membersRole.id)?.deny === '2048'
13 Replies
d.js toolkit
d.js toolkit5mo ago
Velistina
Velistina5mo ago
If i remember right those bits are number based not string
Chaito
ChaitoOP5mo ago
theyre string coming from the API call my question is more about using discordjs types to not check directly like i do in the code right now
Amgelo
Amgelo5mo ago
it's a bitfield, you can parse it as a bigint and use the bitwise and to check if the bit is present for the position you want https://discord.com/developers/docs/topics/permissions#permissions-bitwise-permission-flags
Chaito
ChaitoOP5mo ago
oh ok i get it, thanks!
Chaito
ChaitoOP5mo ago
No description
Amgelo
Amgelo5mo ago
no, the flag is already the bitfield, not the bit position I believe you'll have to code the positions manually, I don't think discord-api-types has an enum for that you can add a check to your current code , like (bitfield & flag) === flag and it should work but, PermissionsBitField is a djs object, why are you using raw data with rest if you're using djs?
Chaito
ChaitoOP5mo ago
No description
Chaito
ChaitoOP5mo ago
im using discordrest.get which returns it as a string thanks so much, ive never worked with bitfields directly this works already :waveBoye:
Amgelo
Amgelo5mo ago
that doesn't answer my question though if you want to work with raw data entirely you can use @discordjs/core
Chaito
ChaitoOP5mo ago
@discordjs/rest doesnt have PermissionsBitField im not using @discordjs
Amgelo
Amgelo5mo ago
PermissionsBitField.Flags is a re-export of PermissionFlagsBits from discord-api-types unless you're not only using Flags, but then I'd say you could copy the functionality you need instead
Chaito
ChaitoOP5mo ago
i chose REST because its an API endpoint not a bot use-case oh im being dumb and the main package has exports for them anyway

Did you find this page helpful?