channelUpdate compare permissions

Hey there, I tried using the channelUpdate event to get the difference between the old permissions and the new channel permissions. There is a slight issue though. Upon using this line to check if the permissions are changed, it always logs false in console, making the permissions check basically usesless.
if(oldChannel.permissionOverwrites.cache == newChannel.permissionOverwrites.cache){
console.log(true)
} else console.log(false)

// it always shows false in this case
if(oldChannel.permissionOverwrites.cache == newChannel.permissionOverwrites.cache){
console.log(true)
} else console.log(false)

// it always shows false in this case
7 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!
d.js docs
d.js docs14mo ago
method Collection#difference() The difference method returns a new structure containing items where the key is present in one of the original structures but not the other.
TehPig
TehPigOP14mo ago
So by changing the if condition to
if(oldChannel.permissionOverwrites.cache.difference(newChannel.permissionOverwrites.cache)){
console.log(true)
} else console.log(false)
if(oldChannel.permissionOverwrites.cache.difference(newChannel.permissionOverwrites.cache)){
console.log(true)
} else console.log(false)
should log true instead? because once I tried it and changed the slowmode of the channel, it logged true in console
treble/luna
treble/luna14mo ago
an empty collection is truthy
TehPig
TehPigOP14mo ago
it would not find the case where a permission is changed instead though it's not empty though
treble/luna
treble/luna14mo ago
regardless, that if statement will always return true
TehPig
TehPigOP14mo ago
old permissions [{"id":"835417069490274344","type":0,"allow":"34628193280","deny":"344134254608"},{"id":"753224027899822160","type":0,"allow":"536871936","deny":"0"}] new permissions [{"id":"753224027899822160","type":0,"allow":"1024","deny":"536870912"},{"id":"835417069490274344","type":0,"allow":"34628193280","deny":"344134254608"}] (using JSON.stringify()) ah in order to detect the change correct? welp, i get the same collection regardless of permission/slowmode changes
Collection(2) [Map] {
'835417069490274344' => PermissionOverwrites {
id: '835417069490274344',
type: 0,
deny: PermissionsBitField { bitfield: 343597383696n },
allow: PermissionsBitField { bitfield: 35165064192n }
},
'753224027899822160' => PermissionOverwrites {
id: '753224027899822160',
type: 0,
deny: PermissionsBitField { bitfield: 536870912n },
allow: PermissionsBitField { bitfield: 1024n }
}
}
Collection(2) [Map] {
'835417069490274344' => PermissionOverwrites {
id: '835417069490274344',
type: 0,
deny: PermissionsBitField { bitfield: 343597383696n },
allow: PermissionsBitField { bitfield: 35165064192n }
},
'753224027899822160' => PermissionOverwrites {
id: '753224027899822160',
type: 0,
deny: PermissionsBitField { bitfield: 536870912n },
allow: PermissionsBitField { bitfield: 1024n }
}
}
The issue which prevents the old permissions to be the same as the new permissions upon slowmode change is just the fact that the permissions are given in different positions within the array I removed .difference it did not affect the result the changed permissions is just me testing if the check actually works
Want results from more Discord servers?
Add your server