Manufacture PermissionOverwrites object

I'm wondering if it's possible to manufacture a PermissionOverwrites object. I can create an object with all the same properties, but the API rejects the object. When I compare to one in the cache I can see that the object itself has a type of PermissionOverwrites:
PermissionOverwrites object pulled from cache:
PermissionOverwrites {
id: '191458771837386752',
type: 'member',
deny: Permissions { bitfield: 377957122048n },
allow: Permissions { bitfield: 3072n }
}

PermissionOverwrites I created:
{
id: '191458771837386752',
type: 'member',
deny: Permissions { bitfield: 377957122048n },
allow: Permissions { bitfield: 3072n }
}
PermissionOverwrites object pulled from cache:
PermissionOverwrites {
id: '191458771837386752',
type: 'member',
deny: Permissions { bitfield: 377957122048n },
allow: Permissions { bitfield: 3072n }
}

PermissionOverwrites I created:
{
id: '191458771837386752',
type: 'member',
deny: Permissions { bitfield: 377957122048n },
allow: Permissions { bitfield: 3072n }
}
I figured out how to create a Permissions object within the overwrite, but I can't seem to figure out how to make the overwrite object itself a PermissionOverwrites object.
3 Replies
megatank58
megatank583y ago
what exactly are you trying to do and what's the api error
ninbura
ninburaOP3y ago
I have a /channel-list function that allows users to join channels, when a channel is joined the corresponding button displays green. Sometimes the cache isn't updating fast enough, so the function that changes the color of the buttons doesn't know that a button's color needs to be updated. Rather than fetching the channels, which results in hitting the API, I thought I could just add to the cache. But pushing a user ID with anything but a real PermissionOverwrites object results in an error (this may be from somewhere else in the bot which looks at overwrites):
/app/node_modules/discord.js/src/structures/PermissionOverwrites.js:35
if ('type' in data) {
/app/node_modules/discord.js/src/structures/PermissionOverwrites.js:35
if ('type' in data) {
First tried just pushing to the Map with random text:
const permissionOverwrites = channel.permissionOverwrites.cache,
memberOverwrite = permissionOverwrites.get(member.id)

if (!memberOverwrite) permissionOverwrites.set(member.id, 'foo')
const permissionOverwrites = channel.permissionOverwrites.cache,
memberOverwrite = permissionOverwrites.get(member.id)

if (!memberOverwrite) permissionOverwrites.set(member.id, 'foo')
ninbura
ninburaOP3y ago
But honestly, maybe rather than messing with the cache I should just pass the button function a channel ID and change the color of the button regardless of what the cache says.
Want results from more Discord servers?
Add your server