mirror of
https://github.com/arthur-pbty/gestion.git
synced 2026-06-03 23:36:35 +02:00
57 lines
2.3 KiB
JavaScript
57 lines
2.3 KiB
JavaScript
const { ChannelType } = require("discord.js")
|
|
module.exports = {
|
|
name: 'sync',
|
|
description: "Synchronise les permissions d'un salon avec sa catégorie ou synchronise tous les salons d'une catégorie.",
|
|
category: 'gestion',
|
|
emote: '🔄',
|
|
utilisation: 'sync [#salon/id/all]',
|
|
async execute(message, args, client) {
|
|
let channel;
|
|
if (args[0] === 'all') {
|
|
channel = message.channel;
|
|
} else {
|
|
channel = message.mentions.channels.first() || message.guild.channels.cache.get(args[0]) || message.channel;
|
|
}
|
|
if (!channel) {
|
|
return message.reply("Je n'ai pas pu trouver le salon ou la catégorie spécifiée.");
|
|
}
|
|
|
|
const category = channel.parent;
|
|
if (!category) {
|
|
return message.reply("Le salon spécifié n'a pas de catégorie associée.");
|
|
}
|
|
try {
|
|
if (args[0] === 'all') {
|
|
const children = category.children.cache;
|
|
if (children && children.size > 0) {
|
|
children.forEach(childChannel => {
|
|
const permissions = category.permissionOverwrites.cache.map(perm => ({
|
|
id: perm.id,
|
|
allow: perm.allow,
|
|
deny: perm.deny,
|
|
type: perm.type
|
|
}));
|
|
childChannel.permissionOverwrites.set(permissions);
|
|
});
|
|
message.reply(`🔄 Tous les salons de la catégorie <#${category.id}> ont été synchronisés.`);
|
|
} else {
|
|
message.reply("La catégorie spécifiée ne contient pas de salons.");
|
|
}
|
|
|
|
} else {
|
|
const permissions = channel.parent.permissionOverwrites.cache.map(perm => ({
|
|
id: perm.id,
|
|
allow: perm.allow,
|
|
deny: perm.deny,
|
|
type: perm.type
|
|
}));
|
|
channel.permissionOverwrites.set(permissions);
|
|
message.reply(`🔄 Le salon <#${channel.id}> a été synchronisé avec sa catégorie.`);
|
|
}
|
|
} catch (error) {
|
|
console.error(error);
|
|
message.reply("Je n'ai pas la permission de gérer les salons ou les catégories.");
|
|
}
|
|
|
|
},
|
|
}; |