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

boucher

discord-bot

Public
Like
discord-bot
Home
Code
18
vt-discord
4
.cursorrules
.env.example
.vtignore
DISCORD_BOT_SETUP.md
README.md
anthropic-service.js
database.js
deno.json
discord-client.js
discord-commands.js
index.js
interactions-endpoint.js
link-analyzer.js
package.json
query-service.js
C
val-town-cron.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
/
README.md
Code
/
README.md
Search
5/2/2025
Viewing readonly version of main branch: v36
View latest version
README.md

Discord DM Analyzer

A Discord bot that analyzes direct messages between you and your partner, allowing you to search and query conversation history, track shared links, and more. Perfect for finding those furniture links you shared months ago!

Features

  • Message History Storage: Securely stores your DM history in a SQLite database
  • Link Detection & Categorization: Automatically detects and categorizes links shared in conversations
  • AI-Powered Querying: Ask natural language questions about your conversation history
  • Furniture Focus: Special features for tracking furniture links and discussions
  • Val.town Integration: Runs on Val.town for easy deployment and scheduling
  • Periodic Updates: Automatically fetches new messages on a schedule

Use Cases

  • "Show me all the sofas we discussed last month"
  • "What did we say about the IKEA table?"
  • "Find all the furniture links we shared since January"
  • "Summarize our discussion about the dining room"

Setup Instructions

Prerequisites

  • Node.js 16+ and npm
  • Discord account with Bot token
  • OpenAI API key (for AI-powered queries)
  • Val.town account (for deployment)

Local Development Setup

  1. Clone this repository

    git clone <repository-url>
    cd discord-bot
    
  2. Install dependencies

    npm install
    
  3. Create a .env file based on .env.example

    cp .env.example .env
    
  4. Fill in the required environment variables in .env:

    • DISCORD_TOKEN: Your Discord bot token
    • DISCORD_CLIENT_ID: Your Discord application client ID
    • DISCORD_USER_ID: Your Discord user ID
    • SPOUSE_USER_ID: Your partner's Discord user ID
    • OPENAI_API_KEY: Your OpenAI API key
  5. Initialize the database

    node index.js
    
  6. Test the DM fetching process

    node val-town-cron.js
    

Val.town Deployment

  1. Install the Val.town CLI

    npm install -g val-town-cli
    
  2. Authenticate with Val.town

    vt login
    
  3. Deploy the application to Val.town

    node val-town-deploy.js
    
  4. Configure Val.town environment variables

    • Go to the Val.town dashboard
    • Add the same environment variables from your .env file
  5. Set up a scheduled task on Val.town for periodic DM fetching

    • Create a new scheduled task using the Val.town dashboard
    • Use the discordDMBotCron function
    • Set the schedule (e.g., every 6 hours)

Creating a Discord Bot

  1. Go to the Discord Developer Portal
  2. Create a New Application
  3. Go to the "Bot" tab and create a bot
  4. Under "Privileged Gateway Intents", enable:
    • Message Content Intent
    • Server Members Intent
  5. Copy the bot token to your .env file
  6. Invite the bot to your server using the OAuth2 URL Generator
    • Select "bot" scope
    • Select permissions: Read Messages/View Channels, Read Message History
  7. Start a DM with your partner to create the DM channel the bot will monitor

API Endpoints

The application exposes the following HTTP endpoints:

  • GET /health: Health check endpoint
  • POST /api/fetch-dms: Manually trigger DM fetching
  • POST /api/process-links: Manually trigger link processing
  • POST /api/query: Submit a query about your message history
    • Body: { "query": "your question here", "filters": { optional filters } }
  • POST /api/commands/search: Discord command endpoint for searching
    • Body: { "query": "your search term" }

Discord Commands

Once set up, you can interact with the bot using the following commands:

  • /search [query]: Search your conversation history
  • /links [category]: Show links from a specific category
  • /categories: List all available link categories
  • /analyze [query]: Analyze your conversation with AI

Database Schema

The application uses a SQLite database with the following tables:

  • messages: Stores all DM messages
  • attachments: Stores message attachments
  • embeds: Stores message embeds
  • links: Stores extracted links with categories
  • categories: Stores link categories
  • conversations: Stores AI-generated conversation summaries

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

License

This project is licensed under the MIT License - see the LICENSE file for details.

Acknowledgements

  • Discord.js for Discord API integration
  • OpenAI for AI-powered querying
  • Val.town for hosting and scheduling
  • Better-SQLite3 for database management
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.