From 9fe5ccc30801eab62d70eed5366796d1ee245113 Mon Sep 17 00:00:00 2001 From: Joren Date: Fri, 28 Jun 2024 00:59:36 +0200 Subject: [PATCH] Save in json format --- index.ts | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/index.ts b/index.ts index b2fdb80..9e36316 100644 --- a/index.ts +++ b/index.ts @@ -15,15 +15,29 @@ class InfoClient extends Client { private onReady(): void { console.log(`Logged in as ${this.user?.tag}!`); + + const guildData: { [key: string]: { [key: string]: string[] } } = {}; this.guilds.cache.forEach((guild: Guild) => { + const guildInfo: { [key: string]: string[] } = {}; console.log(`Guild: ${guild}`); const channels = guild.channels.cache; console.log(`There are ${channels.size} channels in the guild.`); channels.forEach(channel => { - console.log(`- ${channel.name} (${channel.type} ${channel.id})`); + if (channel && channel.type !== 'GUILD_CATEGORY') { + const categoryName = channel.parent?.name || 'Uncategorized'; + const categoryID = channel.parent?.id || 'Uncategorized'; + + if (!guildInfo[categoryName]) { + guildInfo[categoryName] = []; + } + + guildInfo[categoryName].push(`${channel.name} (${channel.type} ${channel.id})`); + } }); + guildData[guild.name] = guildInfo; }); + console.log(guildData) process.exit(); } }