Log channel's permissions update
Hi, when i update one permission, all good, the log is correct.
18 Replies
- 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!But when i update multiples permissions like :
ManageChannels : default to deny
ManageRoles : default to allow
The log is incorrect and tell me that both permissions are now deny
And sometimes it logs only one permission and not all of it
I think it's because i have a forEach on a const multiple times but i don't know how to fix it
Also i think i have to remove elses
Any one ? :c
To make your code more readable (and easier for us to help you with) consider using a beautifier.
- Quick online tool: beautifier.io
- Script and Editor integrations: prettier
To share long code snippets, use a service like gist, sourcebin, starbin, or similar instead of posting them as large code blocks or files.
Code : https://starb.in/LVAE0o.js
what does all of this mean
i dont think thats in djs
Documentation suggestion for @mallusrgreat:
:method: PermissionsBitField#missing()
Gets all given bits that are missing from the bitfield.
Oh thx, i was looking for this
So if anyone has ideas, just tell me 🙂
Nobody ?
https://starb.in/LuQATJ.js
I change the code.
I do forEach cause nexPermissions is an array
Now it's pretty good but i still have to fix one last thing
When i'm editing permissions on ONE role, logs are correct
Hmm so, do i have to get back the older version on my code ?
Ok so with my last one, i have to only have one for each on the roles that have overwrites (but how can i have them? in newPermissionsOverwrites.cache ?) and remove this one newPermissionsOverwrites.cache.forEach((newPermissions, key) => {
I'm a bit confused here 😅
If i look at my last version of the code.
I have to only have one for each on the roles that have overwrites and remove this one newPermissionsOverwrites.cache.forEach((newPermissions, key) => { ?
And remove the 6 forEach and use something like this const newPermissions = newPermissionsOverwrites.cache.get(role.id) ?
Hmm I’ll check how to do this, I hope it won’t take me long
I don't really see how can i only loop over all changed permissions before updating log description with the state of the permission (allow, deny or default)
So now, i only have this :
Is that what you said ? But i don't see what i can do whith this
@Qjuh It's not working at 100% for now
roleName is always = everyone
if perm is allowed or denied and i switch it to default, it's not working
Thank you. Do you have any idea for when i switch to default ?
I didn’t have much time so I did this quickly without testing. I’ll see a little later
And if it's a member how can i get him ? 🤔
Same for missingAllowInOld inside the loop of missingAllowInNew ?
With this system how can i know when perm = default ?
Oh yeah mb, i forget this basic thing
The state before is not really important.
I want to see if it's now default.
For the role name i can do this ? : const roleName = newChannel.guild.roles.cache.get(key) |.| (search member with id) "@everyone";
I will test after when I’m back on my pc
I quickly checked what we discussed.
I don’t understand how to set the perm to and do this rolePermissions.default.push(“🔳 | ${permission}”)
Everything else is correct?
Here is my code :
``js
else {
embed.setTitle("Modification des permissions d'un salon");
embed.setDescription(
Les permissions du salon ${newChannel.toString()} ont été modifiées ! \n)
for (const [key, newPermissions] of newPermissionsOverwrites.cache) {
const oldPermissions = oldPermissionsOverWrites.cache.get(key);
const missingAllowInNew = newPermissions.allow.missing(oldPermissions.allow);
const missingAllowInOld = oldPermissions.allow.missing(newPermissions.allow);
const missingDenyInNew = newPermissions.deny.missing(oldPermissions.deny);
const missingDenyInOld = oldPermissions.deny.missing(newPermissions.deny);
const rolePermissions = {
allowed: [],
denied: [],
default: []
};
//rolePermissions.default.push(
🔳 | ${permission});
missingAllowInNew.forEach(permission => {
if (!missingAllowInOld.includes(permission))
rolePermissions.allowed.push(
✅ | ${permission});
});
missingAllowInOld.forEach(permission => {
if (newPermissions.allow.has(permission))
rolePermissions.allowed.push(
✅ | ${permission});
});
missingDenyInNew.forEach(permission => {
if (!missingDenyInOld.includes(permission))
rolePermissions.denied.push(
❌ | ${permission});
});
missingDenyInOld.forEach(permission => {
if (newPermissions.deny.has(permission))
rolePermissions.denied.push(
❌ | ${permission}`);
});
if (rolePermissions.allowed.length > 0 rolePermissions.denied.length > 0 || rolePermissions.default.length > 0) {
let roleName = newChannel.guild.roles.cache.get(key)?.name ?? await newChannel.guild.members.fetch(key);
if (roleName?.user?.globalName)
roleName = roleName.user.globalName;
else if (roleName?.user?.username)
roleName = roleName.user.username;
embed.data.description += \n**${roleName}**\n
;
if (rolePermissions.allowed.length > 0)
embed.data.description += rolePermissions.allowed.join('\n') + '\n';
if (rolePermissions.default.length > 0)
embed.data.description += rolePermissions.default.join('\n') + '\n';
if (rolePermissions.denied.length > 0)
embed.data.description += rolePermissions.denied.join('\n') + '\n';
}
};
}
js
missingAllowInNew.forEach(permission => {
if (!missingDenyInOld.includes(permission) && !missingDenyInNew.includes(permission))
rolePermissions.default.push(🔳 | ${permission}
);
else if (!missingAllowInOld.includes(permission))
rolePermissions.allowed.push(✅ | ${permission}
);
});
missingAllowInOld.forEach(permission => {
if (newPermissions.allow.has(permission))
rolePermissions.allowed.push(✅ | ${permission}
);
});
missingDenyInNew.forEach(permission => {
if (!missingAllowInOld.includes(permission) && !missingAllowInNew.includes(permission))
rolePermissions.default.push(🔳 | ${permission}
);
else if (!missingDenyInOld.includes(permission))
rolePermissions.denied.push(❌ | ${permission}
);
});
missingDenyInOld.forEach(permission => {
if (newPermissions.deny.has(permission))
rolePermissions.denied.push(❌ | ${permission}
);
});
```
I just added the default perm detection, and now when I change a allow perm to deny or deny to allow, it logs me this and I don’t understand why because it worked before:
✅ | ManageChannels
❌ | ManageChannelsI completely forgot but if I update the perm of two channel's roles, the channelUpdate event is fired twice and I got this in my logs
yeah thats expected
How can i "fix" this ?
I dont know what you mean. Each role change is a channel update. You have to save them individually
By "fix", i mean only have one log with all changes
Well you'd have to implement some sort of queue and wait until you think no more changes are coming and then decide to log all of them
Not at all worth it to fix something that isnt broken
Yeah it's not broken but i only want one log
I clean my code : https://starb.in/0C8Rmd.typescript
But now when i'm updating channel's perms, it doesn't work anymore.
For example if i edit only one perm of everyone role, i got this log :
Modification des permissions d'un salon
Les permissions du salon aaaaa ont été modifiées !
everyone
✅ | ViewChannel
Tojikimado
✅ | ViewChannel
A
✅ | ViewChannel
K
✅ | ViewChannel
Channel modifié par Tojikimado•Aujourd’hui à 16:26
If i edit one perm in 2 roles (everyone & K), i got this logs :
Modification des permissions d'un salon
Les permissions du salon aaaaa ont été modifiées !
K
❌ | ViewChannel
Tojikimado
❌ | ViewChannel
everyone
❌ | ViewChannel
❌ | ViewChannel
Channel modifié par Tojikimado•Aujourd’hui à 16:27
Modification des permissions d'un salon
Les permissions du salon aaaaa ont été modifiées !
K
❌ | ViewChannel
Tojikimado
❌ | ViewChannel
everyone
❌ | ViewChannel
Channel modifié par Tojikimado•Aujourd’hui à 16:27
Am I missing something ?
I haven’t changed anything and it works fine when I change the perms of a role.
It still doesn’t work when I was editing multiple roles, but it’s normal because I still haven’t managed it
Here’s my code: https://starb.in/KTwWnt.typescript
I still can’t manage when I update the perms of two channel'sroles, the channelUpdate event is fired twice and I got 2 logs but I only want one log with all the changes.