• Townie
    AI
  • Blog
  • Docs
  • Pricing
  • We’re hiring!
Log inSign up
boucher

boucher

discord-bot

Public
Like
discord-bot
Home
Code
7
vt-discord
4
DISCORD_BOT_SETUP.md
database.js
discord-commands.js
index.js
link-analyzer.js
val-town-deploy.js
Branches
1
Pull requests
Remixes
History
Environment variables
7
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
/
vt-discord
/
README.md
Code
/
vt-discord
/
README.md
Search
5/2/2025
Viewing readonly version of main branch: v25
View latest version
README.md

Discord DM Analyzer for Val.town

This project is a Discord bot that analyzes direct messages between two users (e.g., you and your partner), particularly focusing on:

  1. Tracking and categorizing shared links
  2. Searching conversation history
  3. Summarizing discussions on specific topics
  4. Analyzing furniture-related discussions

Architecture

The project is structured to work with Val.town and has the following components:

  • Database Layer: Uses Val.town's built-in SQLite database
  • AI Integration: Leverages Anthropic's Claude API for analysis
  • Discord Integration:
    • Bot token for fetching messages
    • Slash commands for user interactions
    • Webhook endpoint for Discord interactions
  • API Endpoints: Various endpoints for manual operations and automation

Setup

Environment Variables

To run this project on Val.town, you need to set up the following environment variables:

  • DISCORD_TOKEN: Your Discord bot token
  • DISCORD_CLIENT_ID: Your Discord application ID
  • DISCORD_PUBLIC_KEY: Public key for verifying Discord interactions
  • DISCORD_USER_ID: Your Discord user ID
  • SPOUSE_USER_ID: Your partner's Discord user ID
  • ANTHROPIC_API_KEY: Your Anthropic API key

Discord Bot Setup

  1. Create a Discord application: https://discord.com/developers/applications
  2. Add a bot to your application
  3. Set the required permissions:
    • Read Messages/View Channels
    • Read Message History
    • Send Messages
  4. Enable the Message Content Intent in the Bot section
  5. Use the OAuth2 URL Generator to create an invite link with the bot scope
  6. Add the bot to a server where both you and your partner are members

Val.town Deployment

  1. Create a new Val on Val.town
  2. Copy the contents of the backend directory
  3. Set up the required environment variables
  4. Create a cron schedule for periodically fetching messages and processing links

Usage

API Endpoints

  • GET /health: Check if the service is running
  • POST /api/interactions: Discord interactions endpoint
  • POST /api/fetch-dms: Manually trigger DM fetching
  • POST /api/process-links: Manually trigger link processing
  • POST /api/query: Process a query about your messages
  • POST /api/commands/search: Endpoint for search commands
  • POST /api/register-commands: Register Discord slash commands
  • GET /api/cron/fetch-dms: Cron endpoint for fetching DMs
  • GET /api/cron/process-links: Cron endpoint for processing links

Discord Commands

The bot provides several slash commands:

  • /search [query]: Search your conversation history
  • /links [category]: Find links shared in conversations, optionally filtered by category
  • /categories: List all available link categories
  • /analyze [query]: Perform a deeper analysis of your conversations

Development

Local Development

  1. Clone the repository
  2. Create a .env file with the required environment variables
  3. Install dependencies with deno cache --reload index.ts
  4. Run locally with deno run --allow-net --allow-env index.ts

Frontend

A basic frontend is provided in the frontend directory. For now, we're focusing on the backend functionality, but the frontend can be extended to provide a web interface for searching and visualizing conversation data.

Val.town Specific Considerations

  • The database uses Val.town's built-in SQLite database
  • The code uses Deno and ESM modules compatible with Val.town
  • HTTP endpoints are designed to work with Val.town's serverless model
  • Discord verification is implemented according to Discord's security requirements

Credits

This project was ported from a Node.js implementation to work specifically with Val.town's environment.

FeaturesVersion controlCode intelligenceCLI
Use cases
TeamsAI agentsSlackGTM
ExploreDocsShowcaseTemplatesNewestTrendingAPI examplesNPM packages
PricingNewsletterBlogAboutCareers
We’re hiring!
Brandhi@val.townStatus
X (Twitter)
Discord community
GitHub discussions
YouTube channel
Bluesky
Terms of usePrivacy policyAbuse contact
© 2025 Val Town, Inc.