import discord
import asyncio

TOKEN = "MTU0NjUxODgyNDQ3NDY0MDQwNA.G4Wd6r.p2MnuyGIYuthaCiquKsYDfOv7cGFLvVaB0bSzs"
THREAD_ID = 1546370630826594434

intents = discord.Intents.default()
intents.message_content = True

client = discord.Client(intents=intents)

@client.event
async def on_ready():
    print(f"Logged in as {client.user}")
    
    # Fetch the thread directly
    thread = client.get_channel(THREAD_ID)
    if thread is None:
        # Try fetching from API
        thread = await client.fetch_channel(THREAD_ID)
    
    if thread is None:
        print(f"Thread {THREAD_ID} not found")
        await client.close()
        return
    
    print(f"\n=== Thread: {thread.name} (ID: {thread.id}) ===\n")
    
    # Read messages
    count = 0
    async for msg in thread.history(limit=200):
        count += 1
        content = msg.content[:300] if msg.content else "[no text content]"
        print(f"[{msg.author}] {content}")
        if msg.attachments:
            for att in msg.attachments:
                print(f"  [ATTACHMENT] {att.url}")
        print()
    
    print(f"\n--- Total messages: {count} ---")
    await client.close()

client.run(TOKEN)
