import discord
import asyncio
import aiohttp
import random
import time
import sys

if sys.platform.startswith('win'):
    import asyncio
    asyncio.set_event_loop_policy(asyncio.WindowsSelectorEventLoopPolicy())

class DiscordBot:
    def __init__(self):
        self.tokens = self.load_tokens()
        self.user_agents = [
            "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36",
            "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/14.1.1 Safari/605.1.15",
            "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/92.0.4515.107 Safari/537.36"
        ]

    def load_tokens(self):
        with open('token.txt', 'r') as file:
            return [line.strip() for line in file if line.strip()]

    async def join_server(self, invite_link):
        async with aiohttp.ClientSession() as session:
            for token in self.tokens:
                headers = {
                    'Authorization': f'Bearer {token}',
                    'User-Agent': random.choice(self.user_agents)
                }
                invite_code = invite_link.split('/')[-1]
                api_url = f'https://discordapp.com/api/v9/invites/{invite_code}'
                
                async with session.post(api_url, headers=headers) as response:
                    if response.status == 200:
                        print(f"Successfully joined server with invite: {invite_link} using token: {token[:10]}...")
                    else:
                        print(f"Failed to join server using token: {token[:10]}... Status code: {response.status}")
                await asyncio.sleep(random.uniform(1, 3))

    async def send_message(self, channel_id, message):
        async with aiohttp.ClientSession() as session:
            while True:
                for token in self.tokens:
                    headers = {
                        'Authorization': f'Bearer {token}',
                        'User-Agent': random.choice(self.user_agents),
                        'Content-Type': 'application/json'
                    }
                    api_url = f'https://discordapp.com/api/v9/channels/{channel_id}/messages'
                    data = {'content': message}
                    
                    async with session.post(api_url, headers=headers, json=data) as response:
                        if response.status == 200:
                            print(f"Message sent successfully to channel {channel_id} using token: {token[:10]}...")
                        else:
                            print(f"Failed to send message using token: {token[:10]}... Status code: {response.status}")
                            response_text = await response.text()
                            print(f"Response: {response_text}")
                
                await asyncio.sleep(random.uniform(1, 5))  # Random delay between 1 and 5 seconds

    async def run(self):
        while True:
            print("\n1. Join server")
            print("2. Send message")
            print("3. Exit")
            choice = input("Enter your choice: ")

            if choice == '1':
                invite = input("Enter the invite link: ")
                await self.join_server(invite)
            elif choice == '2':
                channel = input("Enter the channel ID: ")
                message = input("Enter your message: ")
                await self.send_message(channel, message)
            elif choice == '3':
                print("Exiting...")
                break
            else:
                print("Invalid choice. Please try again.")

if __name__ == "__main__":
    bot = DiscordBot()
    asyncio.run(bot.run())


how does this bot work?