#How to use a bitfield from permissionOverwrite.get() with .create()?

25 messages · Page 1 of 1 (latest)

hoary jasper
#

How do I convert a bitfield from permissionOverwrites.cache.get() .allow.bitfield into permissionOverwrites that can be used with permissionOverwrites.create()?

One is a boolean list of values while the other is a bitfield. Ideally, it would be great to fire the same bitfield back in with a new id.

Basically I need to copy the allow and deny from a specific role in a few channels and then add the same permissions to specific users.

hardy nicheBOT
#

• What's your exact discord.js npm list discord.js and node node -v version?
• Post the full error stack trace, not just the top part!
• Show your code!
• Explain what exactly your issue is.
• Not a discord.js issue? Check out #useful-servers.

hoary jasper
next venture
#

since you're updating the permission overwrites for multiple users, it'd be better to use permissionOverwrites.set()
fortunately, this actually makes it easier to achieve your goal
<GuildChannel>.permissionOverwrites.set() takes an array of overwrite resolvables, for which you can use OverwriteData objects
OverwriteData objects have the allow and deny properties, which are PermissionResolvables, which means you can pass the bitfields from <PermissionOverwrites>.allow and <PermissionOverwrites>.deny respectively

hardy nicheBOT
next venture
#

tldr: in the example on the docs, where it passes an array for deny, you can pass a bitfield

hoary jasper
#

Seems inefficient to have to process all of the other roles to be in that format.

next venture
#

in what way would that be inefficient?
it sounds like you're already processing the other roles if you want to copy the permissions to them with permissionOverwrites.create()

hoary jasper
#

I have to remove type from every object.

next venture
#

no you don't?

hoary jasper
#

ok, I'll give it a shot. Only going by the syntax example.

next venture
#

not only does OverwriteData also have a type property, extraneous properties would also be ignored

hoary jasper
#

Unfortunately I am still stuck and I know this is outside of the realm of what discord.js does, so I will go back to reading. I wish this was simpler.
I have no idea how to go from

Collection(5) [Map] {
'576905485983154176' => PermissionOverwrites {
..
},
'1022258426157473873' => PermissionOverwrites {
..
},
'1015409809698332772' => PermissionOverwrites {
..
},
'1022258425465409636' => PermissionOverwrites {
..
},
'574663806928814088' => PermissionOverwrites {
..
}
}

to

{..},{..},{..},{..}

So I can feed it back in.

hardy nicheBOT
#

Documentation suggestion for @hoary jasper:
method Collection#map()
Maps each item to another value into an array. Identical in behavior to Array.map().

next venture
#

this should help 🙂

hoary jasper
#

That is unfortunately where I have been reading since the last time we talked. I have tried several options, but am unfortunately stuck.

#

The closest I came was

  PermissionOverwrites {
    id: '576905485983154176',
    type: 1,
    deny: PermissionsBitField { bitfield: 0n },
    allow: PermissionsBitField { bitfield: 379968n }
  },
  PermissionOverwrites {
    id: '1022258426157473873',
    type: 0,
    deny: PermissionsBitField { bitfield: 0n },
    allow: PermissionsBitField { bitfield: 68608n }
  },
  PermissionOverwrites {
    id: '1015409809698332772',
    type: 0,
    deny: PermissionsBitField { bitfield: 0n },
    allow: PermissionsBitField { bitfield: 68608n }
  },
  PermissionOverwrites {
    id: '1022258425465409636',
    type: 0,
    deny: PermissionsBitField { bitfield: 0n },
    allow: PermissionsBitField { bitfield: 1024n }
  },
  PermissionOverwrites {
    id: '574663806928814088',
    type: 0,
    deny: PermissionsBitField { bitfield: 1024n },
    allow: PermissionsBitField { bitfield: 49216n }
  }
next venture
#

are you trying to copy each permissions overwrites as they are to a new channel, or a single permission's overwrites to all roles/ids in a channel?

hoary jasper
#

The base function is to get the values of a role, apply it to a user, and add them to the same channel.

next venture
#

if it's the same channel, then you don't even need to map the permission overwrites collection
you can just set permission overwrites in the collection and pass the collection back to <PermissionOverwriteManager>.set()

#

'cause it also takes a collection

hoary jasper
#

I thought set would remove all the other permissions

next venture
#

it will remove all other permissions that you don't pass back
meaning if you just add on to the existing permissions and pass all of them back it will keep them

hoary jasper
#

That pretty much puts me back at where I was at the start of this thread. I don't know how to take what I get from .get, .map, or whatever, and use it in a format that 'set' will work with.

dull basin
#

if i understand it, by not touching it at all and passing it directly?