An intelligent Discord bot that automatically tracks and awards XP based on user activities, powered by AI and integrated with Notion for seamless data management.
- π€ AI-Powered XP Detection: Uses Google's Generative AI to intelligently analyze messages and determine XP-worthy activities
- π Notion Integration: Seamlessly stores and manages XP data in Notion databases
- π Vector Database: Utilizes FAISS for efficient similarity search and activity matching
- π³ Containerized: Fully containerized with Docker for easy deployment
- β‘ Real-time Processing: Instant message processing and XP awarding
- π± Discord Integration: Native Discord.js v14 integration with modern slash commands support
xp-discord-bot/
βββ src/
β βββ index.ts # Application entry point
β βββ discord/
β β βββ DiscordBot.ts # Discord bot implementation
β βββ notion/
β β βββ NotionClient.ts # Notion API integration
β βββ ai/
β β βββ AIProcessor.ts # Google AI processing
β βββ vector/
β βββ VectorDB.ts # FAISS vector database
βββ docker-compose.yml # Container orchestration
βββ Dockerfile # Container build instructions
βββ package.json # Dependencies and scripts
βββ tsconfig.json # TypeScript configuration
βββ .env.example # Environment variables template
Before you begin, ensure you have the following installed:
- Node.js (v18 or higher) - Download here
- npm or yarn - Comes with Node.js
- Docker (optional, for containerized deployment) - Download here
- Discord Application - Create one here
- Notion Integration - Set up here
- Google AI API Key - Get one here
-
Clone the repository
git clone <repository-url> cd dappi-beta
-
Install dependencies
npm install
-
Environment Configuration
cp .env.example .env
Fill in your
.envfile with the required credentials:DISCORD_TOKEN=your_discord_bot_token NOTION_API_KEY=your_notion_integration_token NOTION_DATABASE_ID=your_notion_database_id GOOGLE_AI_API_KEY=your_google_ai_api_key
-
Development Mode
npm run dev
For production deployment using Docker:
# Build and start the container
docker-compose up --build
# Run in background
docker-compose up -d --build
# View logs
docker-compose logs -f
# Stop the container
docker-compose down| Script | Description |
|---|---|
npm run dev |
Start development server with hot reload |
npm run build |
Build TypeScript to JavaScript |
npm start |
Start production server |
npm test |
Run test suite |
- Go to Discord Developer Portal
- Create a new application
- Navigate to "Bot" section
- Create a bot and copy the token
- Enable necessary intents (Message Content Intent, Server Members Intent)
- Invite the bot to your server with appropriate permissions
-
Create a new Notion database with the following properties:
- User (Title)
- Activity (Rich Text)
- XP Awarded (Number)
- Date (Date)
- Discord ID (Rich Text)
-
Share the database with your Notion integration
- Message Detection: Bot listens to Discord messages in configured channels
- AI Analysis: Google's Generative AI analyzes message content for XP-worthy activities
- Vector Matching: FAISS vector database matches activities against predefined criteria
- XP Calculation: AI determines appropriate XP amount based on activity type and complexity
- Notion Storage: XP data is stored in Notion database for persistence
- User Feedback: Bot responds with XP award confirmation and current totals
ES Module Error
Error: Must use import to load ES Module
Solution: This project uses ES modules. Ensure you're using the correct Node.js version (18+) and the updated scripts.
Discord Permission Errors
DiscordAPIError: Missing Permissions
Solution: Ensure your bot has the following permissions:
- Send Messages
- Read Message History
- Use Slash Commands
Notion API Errors
NotionAPIError: Unauthorized
Solution: Verify your Notion integration token and database sharing settings.
- π Check the Discord.js Guide
- π Browse Notion API Documentation
- π€ Review Google AI Documentation
We welcome contributions! Here's how you can help:
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
- Follow TypeScript best practices
- Add tests for new features
- Update documentation as needed
- Ensure Docker builds successfully
This project is licensed under the MIT License - see the LICENSE file for details.
If you encounter any issues or have questions:
- π Report a bug
- π‘ Request a feature
- π¬ Join our Discord community
sequenceDiagram
participant Member as π§ Member
participant DiscordBot as π€ DiscordBot
participant VectorDB as π§ VectorDB
participant NotionService as π NotionService
participant MessageTemplates as β¨ MessageTemplates
Member->>DiscordBot: sends message tagging bot with XP-worthy description
DiscordBot->>VectorDB: search(content)
VectorDB-->>DiscordBot: topMatch (name, type, criterionId)
alt No confident match
DiscordBot-->>Member: "Could not match any XP criteria."
else Match found
DiscordBot->>NotionService: findMemberByUsername(usernames)
NotionService-->>DiscordBot: member Notion IDs
DiscordBot->>NotionService: awardXP(payload)
NotionService-->>DiscordBot: success/failure
DiscordBot->>MessageTemplates: getRandom()
MessageTemplates-->>DiscordBot: "Nice work!"
DiscordBot-->>Member: β
XP awarded for **{criterion}** to {usernames}
end
classDiagram
class NotionService {
+fetchXpCriteria() Promise<XpCriteria[]>
}
class XpCriteriaAdapter {
+xpCriteriaToVectorDocs(criteria: XpCriteria[]) VectorDocument[]
}
class VectorManager {
+refreshXpCriteria() Promise<boolean>
}
class VectorDB {
<<interface>>
+buildIndex(docs: VectorDocument[]) Promise<void>
+search(query: string, topK) Promise<VectorDocument[]>
}
class LocalVectorDB {
+buildIndex(docs: VectorDocument[]) Promise<void>
+search(query: string, topK) Promise<VectorDocument[]>
}
class XpCriteria {
-name: string
-type: string
-description: string
-notion_id: string
}
class VectorDocument {
-id: string
-content: string
-metadata: Record<string, any>
}
%% Relationships
VectorManager --> NotionService : uses
VectorManager --> XpCriteriaAdapter : uses
VectorManager --> VectorDB : uses
LocalVectorDB ..|> VectorDB : implements
XpCriteriaAdapter --> XpCriteria : transforms
VectorDB --> VectorDocument : stores