const { createEmbed } = require('../utils/embeds'); const { Colors } = require('../config'); module.exports = { name: 'backup layout', async execute(client, message) { const guildId = process.env.GUILD_ID; const guild = await client.guilds.fetch(guildId); // Fetch all channels and roles await guild.channels.fetch(); await guild.roles.fetch(); const backup = { guild: { name: guild.name, id: guild.id, backupDate: new Date().toISOString(), }, roles: guild.roles.cache .filter(r => r.name !== '@everyone') .sort((a, b) => b.position - a.position) .map(r => ({ name: r.name, color: r.hexColor, position: r.position, hoist: r.hoist, managed: r.managed, permissions: r.permissions.toArray(), })), categories: guild.channels.cache .filter(c => c.type === 4) // GuildCategory .sort((a, b) => a.position - b.position) .map(cat => ({ name: cat.name, position: cat.position, channels: guild.channels.cache .filter(c => c.parentId === cat.id) .sort((a, b) => a.position - b.position) .map(ch => ({ name: ch.name, type: ch.type === 2 ? 'voice' : 'text', position: ch.position, })), })), }; const json = JSON.stringify(backup, null, 2); const buffer = Buffer.from(json, 'utf-8'); const embed = createEmbed({ title: '💾 Server Backup', description: [ `**Guild:** ${guild.name}`, `**Roles:** ${backup.roles.length}`, `**Categories:** ${backup.categories.length}`, `**Total Channels:** ${backup.categories.reduce((sum, c) => sum + c.channels.length, 0)}`, ].join('\n'), color: Colors.SUCCESS, }); await message.reply({ embeds: [embed], files: [{ attachment: buffer, name: `backup-${guild.name.replace(/\s+/g, '-')}-${Date.now()}.json` }], }); }, };