require('dotenv').config();
const { Client, GatewayIntentBits, PermissionsBitField } = require('discord.js');

async function generateInvite() {
    const client = new Client({
        intents: [
            GatewayIntentBits.Guilds,
            GatewayIntentBits.GuildMessages,
            GatewayIntentBits.MessageContent,
        ],
    });

    try {
        await client.login(process.env.BOT_TOKEN);
        
        const invite = client.generateInvite({
            scopes: ['bot', 'applications.commands'],
            permissions: [
                PermissionsBitField.Flags.ViewChannel,
                PermissionsBitField.Flags.SendMessages,
                PermissionsBitField.Flags.EmbedLinks,
                PermissionsBitField.Flags.AttachFiles,
                PermissionsBitField.Flags.UseApplicationCommands,
                PermissionsBitField.Flags.ManageMessages,
            ]
        });

        console.log('\n=== Bot Invite Link Generator ===');
        console.log('\nCurrent Bot Status:');
        console.log(`Name: ${client.user.tag}`);
        console.log(`ID: ${client.user.id}`);
        
        console.log('\nCurrent Servers:');
        if (client.guilds.cache.size === 0) {
            console.log('❌ Bot is not in any servers');
        } else {
            client.guilds.cache.forEach(guild => {
                console.log(`- ${guild.name} (ID: ${guild.id})`);
            });
        }

        console.log('\n=== Invite Link ===');
        console.log('Use this link to invite the bot to your server:');
        console.log(invite);
        
        console.log('\n=== Next Steps ===');
        console.log('1. Click the link above');
        console.log('2. Select your server from the dropdown');
        console.log('3. Keep all permissions checked');
        console.log('4. Click "Authorize"');
        console.log('\nAfter adding the bot:');
        console.log('1. Enable Developer Mode in Discord (User Settings > App Settings > Advanced)');
        console.log('2. Right-click your notification channel');
        console.log('3. Click "Copy ID"');
        console.log('4. Update your .env file with the new channel ID');

    } catch (error) {
        console.error('Error:', error);
    } finally {
        client.destroy();
    }
}

generateInvite().catch(console.error);