This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
This is a Discord.js bot written in TypeScript, built on the Discord Bot TypeScript Template. The bot features a fishing game with an economy system, AI-powered image generation, and OpenAI integration for enhanced interactions.
npm run build # Compile TypeScript to JavaScript
npm start # Start the bot (single instance)
npm run start:manager # Start with shard manager for multiple shards
npm run start:pm2 # Start with PM2 process managernpm run lint # Run ESLint for code linting
npm run lint:fix # Fix auto-fixable linting issues
npm run format # Check code formatting with Prettier
npm run format:fix # Fix code formatting issuesnpm test # Run all tests
npm run test:unit # Run unit tests only
npm run test:integration # Run integration tests only
npm run test:watch # Run tests in watch mode
npm run test:coverage # Run tests with coverage reportnpm run db:generate # Generate database migrations
npm run db:push # Push schema changes to database
npm run db:migrate # Run database migrations
npm run db:seed # Seed database with initial data
npm run db:setup # Push schema and seed data
npm run db:studio # Open Drizzle Studio for database managementnpm run commands:view [GUILD_ID] # View registered commands
npm run commands:register [GUILD_ID] # Register commands (guild-specific if ID provided)
npm run commands:clear [GUILD_ID] # Clear registered commands
npm run commands:rename # Rename a command
npm run commands:delete # Delete a specific command-
Bot Initialization (
src/start-bot.ts,src/start-manager.ts): Entry points for bot and shard manager- Bot setup and configuration
- Command registration
- Event handler initialization
- Service initialization (OpenAI, Database)
-
Commands (
src/commands/): Discord slash commands- Chat Commands:
/fish,/fishing,/shop,/buy,/inventory,/generate-image,/help,/info,/test,/dev - Context Menu Commands: View date sent (message), View date joined (user)
- Command metadata and argument definitions in
metadata.tsandargs.ts
- Chat Commands:
-
Services (
src/services/): Business logic layer- FishingService: Core fishing mechanics and catch logic
- UserService: User data management
- GuildService: Server settings and configuration
- DatabaseService: Database connection and query management (Drizzle ORM)
- OpenAIService: OpenAI API integration for AI features
- ImageUpload: Image upload to fal.ai for AI-generated images
- ItemEffectsService: Item effect calculations (rarity boosts, worth multipliers)
- FishingCooldownService: Rate limiting for fishing commands
- ShopService: Shop and purchase management
-
Database Schema (
src/db/schema.ts): PostgreSQL schema using Drizzle ORM- users: Discord user profiles with money and auto-fishing status
- catchables: Fish and items that can be caught (rarity, worth, images)
- catches: Record of user catches
- items: Purchasable items with effects (consumable/passive)
- shop: Items available for purchase
- purchases: Purchase history
- inventory: User item inventory
- guilds: Server-specific settings (cooldown limits)
-
Events (
src/events/): Discord event handlers- CommandHandler: Slash command execution
- ButtonHandler: Button interaction handling
- MessageHandler: Message event processing
- ReactionHandler: Reaction event processing
- TriggerHandler: Custom trigger system
- GuildJoinHandler: New server welcome messages
- GuildLeaveHandler: Server leave cleanup
-
Utilities (
src/utils/): Helper functions- ClientUtils: Discord client helpers
- CommandUtils: Command processing utilities
- MessageUtils: Message formatting and sending
- PermissionUtils: Permission checking
- DbUtils: Database query helpers
- FormatUtils: Data formatting
- StringUtils: String manipulation
- MathUtils: Mathematical calculations
- RandomUtils: Random number generation
-
Models (
src/models/): Data models and type definitions- ConfigModels: Configuration types
- InternalModels: Internal data structures
- API Models: REST API request/response types for cluster API
-
Fishing Game
- Catch various fish/items with different rarities
- Economy system with money and purchasable items
- Item effects (rarity boosts, worth multipliers)
- Auto-fishing capability
- Cooldown system to prevent spam
-
AI Integration
- OpenAI API for enhanced interactions
- Image generation via fal.ai
- Thread management for conversation context
-
Scalability
- Sharding support for large bot deployments (2500+ servers)
- Clustering support for multi-machine deployment
- PM2 process manager integration
- Cluster API for cross-shard communication
-
Developer Features
- TypeScript with strict type checking
- ESM modules for modern JavaScript
- Comprehensive testing with Vitest
- Database migrations with Drizzle Kit
- Localization support via
lang/directory
- User invokes slash command in Discord
- CommandHandler receives interaction and routes to appropriate Command
- Command validates permissions and arguments
- Command calls relevant Service(s) for business logic
- Service queries/updates database via DatabaseService
- Service applies game logic (e.g., fishing mechanics, item effects)
- Results formatted and sent back to Discord user via MessageUtils
- Handler Pattern: Event handlers process Discord events and route to appropriate components
- Service Layer: Business logic separated from command/event handling
- Repository Pattern: DatabaseService abstracts database operations
- Factory Pattern: Command and event handler registration
- Singleton Pattern: Services like OpenAIService and DatabaseService
- TypeScript:
tsconfig.jsonwith strict type checking, ESM modules - ESLint:
.eslintrc.jsonfor code quality - Prettier:
.prettierrc.jsonfor code formatting - Vitest:
vitest.config.tsfor testing configuration - Drizzle:
src/drizzle.config.tsfor database configuration - Bot Config:
config/config.json(seeconfig/*.example.jsonfor templates) - Build Output:
dist/directory
Required environment variables (typically in .env):
- Discord bot token and client ID
- Database connection string (PostgreSQL)
- OpenAI API key (for AI features)
- fal.ai API key (for image generation)
- Bot developer Discord user ID(s)
- When wanting to create custom migration, use the following command to generate a migration file:
drizzle-kit generate --custom --name=<migration> - Always ensure you're running linting, type checks, builds, and tests after completing features