• Blog
  • Docs
  • Pricing
  • We’re hiring!
Log inSign up
stevekrouse

stevekrouse

auto-thread

Public
Like
2
auto-thread
Home
Code
5
README.md
discord.ts
main.ts
test-autothread.ts
validate-discord-key.ts
Environment variables
1
Branches
1
Pull requests
Remixes
History
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.
Sign up now
Code
/
README.md
Code
/
README.md
Search
2/15/2026
Viewing readonly version of main branch: v20
View latest version
README.md

auto-thread

Automatically creates Discord threads from new messages in configured channels, using OpenAI to generate descriptive thread titles.

How It Works

Rendering mermaid diagram...

Files

FileTypeDescription
main.tsscriptEntry point / orchestrator (currently empty, to be built out)
discord.tsscriptDiscord REST API wrapper — currently hand-rolled, migrating to @discordjs/rest + discord-api-types
test-autothread.tsscriptManual test: fetches last message from #test, generates a title via OpenAI, and creates a thread
validate-discord-key.tsscriptValidates bot token, lists guilds/channels/permissions, and optionally runs a write test

Architecture Decisions

  • 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-rolled discord.ts with the official discord.js REST library for built-in rate limiting, retries, and full TypeScript types.
  • OpenAI for thread titles — uses gpt-4o-mini to generate short, descriptive thread names from message content.

Environment Variables

KeyDescription
DISCORD_BOT_TOKENDiscord bot token with permissions: VIEW_CHANNEL, READ_MESSAGE_HISTORY, SEND_MESSAGES, CREATE_PUBLIC_THREADS

Required Bot Permissions

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)

Planned Improvements

  • Migrate discord.ts to use @discordjs/rest + discord-api-types (Option B: embrace library patterns with Routes.*)
  • Update test-autothread.ts and validate-discord-key.ts to use new API
  • Build out main.ts as an interval-triggered orchestrator
  • Track last-processed message ID (via SQLite or blob) to avoid duplicate threads
  • Make target channels configurable
FeaturesVersion controlCode intelligenceCLIMCP
Use cases
TeamsAI agentsSlackGTM
DocsShowcaseTemplatesNewestTrendingAPI examplesNPM packages
PricingNewsletterBlogAboutCareers
We’re hiring!
Brandhi@val.townStatus
X (Twitter)
Discord community
GitHub discussions
YouTube channel
Bluesky
Open Source Pledge
Terms of usePrivacy policyAbuse contact
© 2026 Val Town, Inc.