Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Discord.JS See If Role Permissions Were Added or Removed

I have an event that triggers when a user changes a roles permissions, I already have it say which permission was updated but I don’t know how to see if it was removed or added

roleUpdate Event:

                if (!oldRole.permissions.equals(newRole.permissions)) {

                    let arr1 = newRole.permissions.toArray()
                    let arr2 = oldRole.permissions.toArray()

                    let difference = arr1
                        .filter(x => !arr2.includes(x))
                        .concat(arr2.filter(x => !arr1.includes(x)));

                    console.log(difference)
                  // would log [ 'MANAGE_CHANNELS' ] if the manage channels permission was removed or added
                 }

I am trying to print something like

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

 + MANAGE_CHANNELS
 - MANAGE_ROLES
 + ADMINISTRATOR

>Solution :

Does this get you unstuck?

const oldPerms = [1, 2, 3, 4, 5, 6];
const newPerms =          [4, 5, 6, 7, 8, 9];

const addedPerms = newPerms
  .filter(p => !oldPerms.includes(p));
const removedPerms = oldPerms
  .filter(p => !newPerms.includes(p));

console.log({addedPerms});
console.log({removedPerms});
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading