#Crash if members do not have a permission.

7 messages · Page 1 of 1 (latest)

rapid osprey
#

So I have implemented checking for permission. I am using, for example, member.has(['MANAGE_GUILD']) and if it returns true it performs the command. When the member has the permission it performs all right but if the member does not have the permission, I get the BITFIELD_INVALID error. Why is that?

#
RangeError [BITFIELD_INVALID]: Invalid bitfield flag or number: MANAGE_GUILD.
    at Function.resolve (/mnt/DATA/general_programming/CL bot/Club-League-Bot/node_modules/discord.js/src/util/BitField.js:168:11)
    at /mnt/DATA/general_programming/CL bot/Club-League-Bot/node_modules/discord.js/src/util/BitField.js:163:54
    at Array.map (<anonymous>)
    at Function.resolve (/mnt/DATA/general_programming/CL bot/Club-League-Bot/node_modules/discord.js/src/util/BitField.js:163:40)
    at PermissionsBitField.has (/mnt/DATA/general_programming/CL bot/Club-League-Bot/node_modules/discord.js/src/util/BitField.js:60:28)
    at PermissionsBitField.has (/mnt/DATA/general_programming/CL bot/Club-League-Bot/node_modules/discord.js/src/util/PermissionsBitField.js:92:82)
    at Client.<anonymous> (/mnt/DATA/general_programming/CL bot/Club-League-Bot/src/bot.js:157:44)
    at Client.emit (node:events:527:28)
    at InteractionCreateAction.handle (/mnt/DATA/general_programming/CL bot/Club-League-Bot/node_modules/discord.js/src/client/actions/InteractionCreate.js:81:12)
    at Object.module.exports [as INTERACTION_CREATE] (/mnt/DATA/general_programming/CL bot/Club-League-Bot/node_modules/discord.js/src/client/websocket/handlers/INTERACTION_CREATE.js:4:36)
Emitted 'error' event on Client instance at:
    at emitUnhandledRejectionOrErr (node:events:384:10)
    at processTicksAndRejections (node:internal/process/task_queues:85:21) {
  [Symbol(code)]: 'BITFIELD_INVALID'
vital hazel
#

So member is a PermissionsBitField in this instance (bad variable naming/would at least need some explanation in your question)
ManageGuild would be a valid value, CamelCase not SCREAMING_SNAKE_CASE

rapid osprey
#

Why did it work when the member actually had the permission tho....

#

Additionally I was just following the names on the official discord website as the documentation mentioned

vital hazel
#

Probably because that if wasn’t reached in that case

vital hazel