Channel Permissions not working (Discord.JS)

Hello everyone,

So I am trying to edit the permissions of a channel with discord, this is the code I have but it doesn’t work!

NewChannel.permissionOverwrites.create(NewChannel.guild.roles.everyone, { ViewChannel: false })

Any help would be appreciated!

Do you get any errors when running the code?

      if (!userOrRole) throw new DiscordjsTypeError(ErrorCodes.InvalidType, 'parameter', 'User nor a Role');
                             ^

TypeError [InvalidType]: Supplied parameter is not a User nor a Role.
    at PermissionOverwriteManager.upsert (C:\Users\maxmo\Documents\GitHub\Westside\node_modules\discord.js\src\managers\PermissionOverwriteManager.js:101:30)
    at PermissionOverwriteManager.create (C:\Users\maxmo\Documents\GitHub\Westside\node_modules\discord.js\src\managers\PermissionOverwriteManager.js:129:17)
    at Client.<anonymous> (C:\Users\maxmo\Documents\GitHub\Westside\index.js:92:37)
    at processTicksAndRejections (node:internal/process/task_queues:96:5) {
  code: 'InvalidType'
}

This error tells us that this is not a Role nor a User.

Yeah I thought that was the issue, but I have used the exact same code in another script and it works

Strange, have you tried comparing the lines after and before this error?

Also, try doing a specific role.

ok I tried this and got a new error

RangeError [BitFieldInvalid]: Invalid bitfield flag or number: SEND_MESSAGES.
    at Function.resolve (C:\Users\maxmo\Documents\GitHub\Westside\node_modules\discord.js\src\util\BitField.js:168:11)
    at C:\Users\maxmo\Documents\GitHub\Westside\node_modules\discord.js\src\util\BitField.js:163:54
    at Array.map (<anonymous>)
    at Function.resolve (C:\Users\maxmo\Documents\GitHub\Westside\node_modules\discord.js\src\util\BitField.js:163:40)
    at Function.resolve (C:\Users\maxmo\Documents\GitHub\Westside\node_modules\discord.js\src\structures\PermissionOverwrites.js:190:34)
    at C:\Users\maxmo\Documents\GitHub\Westside\node_modules\discord.js\src\managers\GuildChannelManager.js:149:81
    at Array.map (<anonymous>)
    at GuildChannelManager.create (C:\Users\maxmo\Documents\GitHub\Westside\node_modules\discord.js\src\managers\GuildChannelManager.js:149:51)
    at Client.<anonymous> (C:\Users\maxmo\Documents\GitHub\Westside\index.js:82:23)
    at Client.emit (node:events:532:35) {
  code: 'BitFieldInvalid'
}
``

Solved it, thanks for the help @cookie

No problem, good luck on your future endeavors!

1 Like

This topic was automatically closed after 7 days. New replies are no longer allowed.