File size: 2,479 Bytes
3c7e34b | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 | 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` }],
});
},
};
|