-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfetch_raw.py
More file actions
executable file
·44 lines (37 loc) · 1.52 KB
/
fetch_raw.py
File metadata and controls
executable file
·44 lines (37 loc) · 1.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#!/usr/bin/env -S uv run
# /// script
# dependencies = ["aiohttp"]
# ///
import aiohttp
import asyncio
import json
import os
async def main():
token = os.environ["DISCORD_TOKEN"]
guild_id = os.environ.get("DISCORD_GUILD", "1354881461060243556")
headers = {
"Authorization": f"Bot {token}",
"User-Agent": "DiscordBot (https://github.com/Open-Athena/discord-agent, 0.1)",
}
base = "https://discord.com/api/v10"
async with aiohttp.ClientSession(headers=headers) as session:
# Test: get current user
async with session.get(f"{base}/users/@me") as r:
user = await r.json()
print(f"Logged in as: {user.get('username', user)}")
async with session.get(f"{base}/guilds/{guild_id}/channels") as r:
channels = await r.json()
print(f"\nChannels ({len(channels)}):")
for ch in channels[:10]:
if ch.get("type") == 0: # text channels
print(f" #{ch['name']} ({ch['id']})")
channel_id = 1415061162701361242
async with session.get(f"{base}/channels/{channel_id}/messages?limit=5") as r:
messages = await r.json()
print(f"\nRecent messages in channel {channel_id}:")
for msg in messages:
author = msg.get("author", {}).get("username", "?")
content = msg.get("content", "")[:60].replace("\n", " ")
ts = msg.get("timestamp", "")[:16]
print(f" {ts} {author}: {content}")
asyncio.run(main())