From 216bb7a6726d5d4e95765350fd8eee777b00dcc3 Mon Sep 17 00:00:00 2001 From: Joren Date: Fri, 28 Jun 2024 01:35:13 +0200 Subject: [PATCH] Write to file --- index.ts | 44 +++++++++++++++++++++++++++++--------------- 1 file changed, 29 insertions(+), 15 deletions(-) diff --git a/index.ts b/index.ts index 6de3499..bb515da 100644 --- a/index.ts +++ b/index.ts @@ -1,7 +1,6 @@ import { Client, Guild } from 'discord.js-selfbot-v13'; import fs from 'fs'; - class InfoClient extends Client { public token: string; @@ -12,8 +11,8 @@ class InfoClient extends Client { } private async init(): Promise { - this.once('ready', () => this.onReady()); - await this.login(this.token); + this.once('ready', () => this.onReady()); + await this.login(this.token); } private onReady(): void { @@ -27,7 +26,7 @@ class InfoClient extends Client { const channels = guild.channels.cache; console.log(`There are ${channels.size} channels in the guild.`); channels.forEach(channel => { - if (channel && channel.type !== 'GUILD_CATEGORY') { + if (channel && channel.type !== 'GUILD_CATEGORY') { const categoryName = channel.parent?.name || 'Uncategorized'; const categoryID = channel.parent?.id || 'Uncategorized'; @@ -36,26 +35,41 @@ class InfoClient extends Client { } guildInfo[categoryName].push(`${channel.name} (${channel.type} ${channel.id})`); - } + } }); guildData[guild.name] = guildInfo; }); - const filename = `${this.user?.tag} ${this.token.substring(0, 5)}.json`; + const filename = `output/${this.user?.tag} ${this.token.substring(0, 5)}.json`; const jsonData = JSON.stringify(guildData, null, 2); fs.writeFileSync(filename, jsonData); - process.exit(); + console.log(`Data saved to ${filename}`); } } -function createInfoClientsFromFile(filePath: string): void { - const tokens = fs.readFileSync(filePath, 'utf-8').split('\n').map(token => token.trim()); +async function createInfoClientsFromFile(filePath: string): Promise { + try { + const tokens = fs.readFileSync(filePath, 'utf-8').split('\n').map(token => token.trim()); - tokens.forEach(token => { - if (token) { - new InfoClient(token); - } - }); + const clientPromises = tokens.map(async token => { + if (token) { + const client = new InfoClient(token); + await client.login(token); + console.log(`Logged in with token: ${token}`); + } + }); + + await Promise.all(clientPromises); + + console.log("All clients logged in successfully."); + process.exit(); + } catch (error) { + console.error('Error creating InfoClients:', error); + process.exit(1); + } } const tokensFilePath = 'tokens.txt'; -createInfoClientsFromFile(tokensFilePath); +createInfoClientsFromFile(tokensFilePath).catch(err => { + console.error('Error creating InfoClients:', err); +}); +