ChannelGrab/index.ts
2024-06-28 01:56:26 +02:00

84 lines
2.5 KiB
TypeScript

import { Client, Guild, Permissions } from 'discord.js-selfbot-v13';
import fs from 'fs';
class InfoClient extends Client {
public token: string;
public constructor(token: string) {
super();
this.token = token;
this.init();
}
private async init(): Promise<void> {
this.once('ready', () => this.onReady());
await this.login(this.token);
}
private onReady(): void {
console.log(`Logged in as ${this.user?.tag}!`);
const guildData: { [key: string]: { [key: string]: { channels: Record<string, { channelname: string, channeltype: string, access: boolean }> } } } = {};
this.guilds.cache.forEach((guild: Guild) => {
const guildInfo: { [key: string]: { channels: Record<string, { channelname: string, channeltype: string, access: boolean }> } } = {};
console.log(`Guild: ${guild.name}`);
guild.channels.cache.forEach(channel => {
if (channel.type !== 'GUILD_CATEGORY') {
const categoryName = channel.parent?.name || 'Uncategorized';
const categoryID = channel.parent?.id || 'Uncategorized';
if (!guildInfo[categoryName]) {
guildInfo[categoryName] = { channels: {} };
}
let access = false;
if (channel.permissionsFor(this.user!)?.has(Permissions.FLAGS.VIEW_CHANNEL)) {
access = true;
}
guildInfo[categoryName].channels[channel.id] = {
channelname: channel.name,
channeltype: channel.type,
access: access
};
}
});
guildData[guild.name] = guildInfo;
});
const filename = `output/${this.user?.tag} ${this.token.slice(-5)}.json`;
const jsonData = JSON.stringify(guildData, null, 2);
fs.writeFileSync(filename, jsonData);
console.log(`Data saved to ${filename}`);
}
}
async function createInfoClientsFromFile(filePath: string): Promise<void> {
try {
const tokens = fs.readFileSync(filePath, 'utf-8').split('\n').map(token => token.trim());
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).catch(err => {
console.error('Error creating InfoClients:', err);
});