Automatically creates Discord threads from new messages in configured channels, using OpenAI to generate descriptive thread titles.
Rendering mermaid diagram...
The cron triggers every 1 minute (requires Val Town Pro — free tier minimum is 15 minutes). Inside each invocation, an inner loop polls all watched channels every 5 seconds for ~55 seconds, then exits to leave headroom before the next cron fires. This gives you near-real-time thread creation without needing a persistent server.
When a channel is first added, the bot does not retroactively thread existing messages. It records the latest message as a cursor and only threads new messages going forward.
| File | Type | Purpose |
|---|---|---|
main.ts | interval | Core loop: poll channels → generate title → create thread |
sqlite.ts | script | Track last-processed message ID per channel |
DISCORD_BOT_TOKEN environment variable in this valbotView ChannelsRead Message HistorySend MessagesCreate Public ThreadsSend Messages in ThreadsEdit the WATCH_CHANNELS array in main.ts with the Discord channel IDs you want to auto-thread.
To get a channel ID: enable Developer Mode in Discord (User Settings → Advanced → Developer Mode), then right-click a channel and click Copy Channel ID.
The interval should be set to 1 minute. Note that the 1-minute interval requires a Val Town Pro subscription (free tier minimum is 15 minutes). If you're on the free tier, set the interval to 15 minutes — the inner loop will still poll every 5 seconds for ~55 seconds each run, but there will be a ~14-minute gap between runs.
npm:@discordjs/rest — Discord REST API with rate limiting and retriesnpm:discord-api-types — Full TypeScript types for the Discord APIstd/openai — Val Town's OpenAI wrapperstd/sqlite — Val Town's project-scoped SQLite