Invalid bitfield in audit log channel permissions event

Hey, I currently have the issue that errors like these are sent multiple times a minute into my bot's console:
RangeError [BitFieldInvalid]: Invalid bitfield flag or number: 3072.
RangeError [BitFieldInvalid]: Invalid bitfield flag or number: 0.
RangeError [BitFieldInvalid]: Invalid bitfield flag or number: 2048.
RangeError [BitFieldInvalid]: Invalid bitfield flag or number: 377959222272.
RangeError [BitFieldInvalid]: Invalid bitfield flag or number: 1048593.
RangeError [BitFieldInvalid]: Invalid bitfield flag or number: 3072.
RangeError [BitFieldInvalid]: Invalid bitfield flag or number: 0.
RangeError [BitFieldInvalid]: Invalid bitfield flag or number: 2048.
RangeError [BitFieldInvalid]: Invalid bitfield flag or number: 377959222272.
RangeError [BitFieldInvalid]: Invalid bitfield flag or number: 1048593.
It seems like this is being sent every time I am trying to parse permissions sent from the Audit Log event ChannelOverwriteCreate/-Update/-Delete. The code causing this error:
// ...
let changes = {};
for (let change of (entry.changes || [])) {
changes[change.key] = [change.old_value, change.new_value];
}
if (changes.allow?.[1]) {
// This line causes the error:
let allow = new Discord.PermissionsBitField(changes.allow[1]).toArray();
// ...
}
// ...
// ...
let changes = {};
for (let change of (entry.changes || [])) {
changes[change.key] = [change.old_value, change.new_value];
}
if (changes.allow?.[1]) {
// This line causes the error:
let allow = new Discord.PermissionsBitField(changes.allow[1]).toArray();
// ...
}
// ...
I am not sure why this would suddenly be an issue, especially because Discord sent those bitfield numbers.
5 Replies
d.js toolkit
d.js toolkit14mo ago
- What's your exact discord.js npm list discord.js and node node -v version? - Not a discord.js issue? Check out #other-js-ts. - Consider reading #how-to-get-help to improve your question! - Explain what exactly your issue is. - Post the full error stack trace, not just the top part! - Show your code! - Issue solved? Press the button! - Marked as resolved by OP
Syjalo
Syjalo14mo ago
Permissions bit field should be a string or a BigInt, not a number.
Xge
XgeOP14mo ago
Oh yeah, it works if I make it a string:
`${changes.allow[1]}`
`${changes.allow[1]}`
Why does it say in the docs that it accepts a number as well though?
No description
Syjalo
Syjalo14mo ago
It depends on what the DefaultBit of the BitField is. For PermissionsBitField it's BigInt. And you'll lose some data if you'll use numbers for permissions since it's larger then the MAX_SAFE_NUMBER.
Xge
XgeOP14mo ago
Alright, thank you very much
Want results from more Discord servers?
Add your server