Channel's Permissions Update

Hi, how can i check if channel's permissions has been changed ? Here is my code :
if(oldChannel.permissionOverwrites.length == newChannel.permissionOverwrites.length)
{
if(oldChannel.name != newChannel.name)
embed.data.description += `**Nom :** \`${oldChannel.name}\`\`${newChannel.name}\``;
if (oldChannel.topic !== newChannel.topic) {
const oldTopic = oldChannel.topic || '';
const newTopic = newChannel.topic || '';
let formattedTopic = '**Sujet du salon :** ';

const differentWords = Diff.diffWords(oldTopic, newTopic);
differentWords.forEach(part => {
if (part.added)
formattedTopic += `**${part.value}** `;
else if (part.removed)
{
if (part.value.trim() === '')
formattedTopic += ' ';
else
{
const spaceBefore = part.value.startsWith(' ') ? ' ' : '';
const spaceAfter = part.value.endsWith(' ') ? ' ' : '';
const valueWithoutSpaces = part.value.trim();
formattedTopic += `${spaceBefore}~~${valueWithoutSpaces}~~${spaceAfter}`;
}
}
else
formattedTopic += part.value;
});

embed.data.description += `${formattedTopic}\n`;
}
if(oldChannel.type != newChannel.type)
embed.data.description += `**Salon d'annonces :** \`${newChannel.type == 5 ? "Activé" : "Désactivé"}\`\n`;
if(oldChannel.nsfw != newChannel.nsfw)
embed.data.description += `**NSFW :** \`${newChannel.nsfw == true ? "Activé" : "Désactivé"}\`\n`;
if(oldChannel.rateLimitPerUser != newChannel.rateLimitPerUser)
embed.data.description += `**Mode lent :** \`${newChannel.rateLimitPerUser == 0 ? "Désactivé" : newChannel.rateLimitPerUser}\`\`${newChannel.rateLimitPerUser == 0 ? "Désactivé" : newChannel.rateLimitPerUser}\`\n`;
}
else
{
embed.setTitle("Modification des permissions d'un salon");

const oldPermissions = oldChannel.permissionOverwrites;
const newPermissions = newChannel.permissionOverwrites;

console.log(oldPermissions);
console.log(newPermissions);
}
if(oldChannel.permissionOverwrites.length == newChannel.permissionOverwrites.length)
{
if(oldChannel.name != newChannel.name)
embed.data.description += `**Nom :** \`${oldChannel.name}\`\`${newChannel.name}\``;
if (oldChannel.topic !== newChannel.topic) {
const oldTopic = oldChannel.topic || '';
const newTopic = newChannel.topic || '';
let formattedTopic = '**Sujet du salon :** ';

const differentWords = Diff.diffWords(oldTopic, newTopic);
differentWords.forEach(part => {
if (part.added)
formattedTopic += `**${part.value}** `;
else if (part.removed)
{
if (part.value.trim() === '')
formattedTopic += ' ';
else
{
const spaceBefore = part.value.startsWith(' ') ? ' ' : '';
const spaceAfter = part.value.endsWith(' ') ? ' ' : '';
const valueWithoutSpaces = part.value.trim();
formattedTopic += `${spaceBefore}~~${valueWithoutSpaces}~~${spaceAfter}`;
}
}
else
formattedTopic += part.value;
});

embed.data.description += `${formattedTopic}\n`;
}
if(oldChannel.type != newChannel.type)
embed.data.description += `**Salon d'annonces :** \`${newChannel.type == 5 ? "Activé" : "Désactivé"}\`\n`;
if(oldChannel.nsfw != newChannel.nsfw)
embed.data.description += `**NSFW :** \`${newChannel.nsfw == true ? "Activé" : "Désactivé"}\`\n`;
if(oldChannel.rateLimitPerUser != newChannel.rateLimitPerUser)
embed.data.description += `**Mode lent :** \`${newChannel.rateLimitPerUser == 0 ? "Désactivé" : newChannel.rateLimitPerUser}\`\`${newChannel.rateLimitPerUser == 0 ? "Désactivé" : newChannel.rateLimitPerUser}\`\n`;
}
else
{
embed.setTitle("Modification des permissions d'un salon");

const oldPermissions = oldChannel.permissionOverwrites;
const newPermissions = newChannel.permissionOverwrites;

console.log(oldPermissions);
console.log(newPermissions);
}
5 Replies
d.js toolkit
d.js toolkit11mo 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! - Marked as resolved by OP
d.js docs
d.js docs11mo 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.
Tojikimado
TojikimadoOP11mo ago
difference() can return an empty value ? So if i have to compare each overwrite's allow and deny values because of that, why use difference() ?
Tojikimado
TojikimadoOP11mo ago
So i have to do a difference method first, and compare one-by-one in the else to find wich one ? Also i got an error : .difference is not a function
No description
Tojikimado
TojikimadoOP11mo ago
Oh ok mb
Want results from more Discord servers?
Add your server