auto-thread
Val Town is a collaborative website to build and scale JavaScript apps.
Deploy APIs, crons, & store data – all from the browser, and deployed in milliseconds.
Viewing readonly version of main branch: v24View latest version
Automatically creates Discord threads from new messages in configured channels, using OpenAI to generate descriptive thread titles.
Rendering mermaid diagram...
| File | Type | Description |
|---|---|---|
main.ts | script | Entry point / orchestrator (currently empty, to be built out) |
discord.ts | script | Discord REST API wrapper — currently hand-rolled, migrating to @discordjs/rest + discord-api-types |
test-autothread.ts | script | Manual test: fetches last message from #test, generates a title via OpenAI, and creates a thread |
validate-discord-key.ts | script | Validates bot token, lists guilds/channels/permissions, and optionally runs a write test |
- REST-only — no gateway/websocket connection. The bot polls for new messages on a schedule rather than listening to real-time events. This fits Val Town's serverless model perfectly.
@discordjs/rest+discord-api-types— replacing the hand-rolleddiscord.tswith the official discord.js REST library for built-in rate limiting, retries, and full TypeScript types.- OpenAI for thread titles — uses
gpt-4o-minito generate short, descriptive thread names from message content.
| Key | Description |
|---|---|
DISCORD_BOT_TOKEN | Discord bot token with permissions: VIEW_CHANNEL, READ_MESSAGE_HISTORY, SEND_MESSAGES, CREATE_PUBLIC_THREADS |
The Discord bot needs these permission flags:
VIEW_CHANNEL(1 << 10)SEND_MESSAGES(1 << 11)READ_MESSAGE_HISTORY(1 << 16)MANAGE_THREADS(1 << 34)CREATE_PUBLIC_THREADS(1 << 35)SEND_MESSAGES_IN_THREADS(1 << 38)
- Migrate
discord.tsto use@discordjs/rest+discord-api-types(Option B: embrace library patterns withRoutes.*) - Update
test-autothread.tsandvalidate-discord-key.tsto use new API - Build out
main.tsas an interval-triggered orchestrator - Track last-processed message ID (via SQLite or blob) to avoid duplicate threads
- Make target channels configurable
