Files
joel/src
2026-02-01 16:55:14 +01:00
..
2026-01-29 12:26:13 +01:00
2026-02-01 16:55:14 +01:00
2026-01-29 12:26:13 +01:00
2026-01-29 12:26:13 +01:00
2026-02-01 16:55:14 +01:00
2026-02-01 16:55:14 +01:00
2026-01-29 12:26:13 +01:00
2026-01-29 12:26:13 +01:00
2026-01-29 12:26:13 +01:00

Joel Discord Bot

A Discord bot with AI-powered responses and message tracking.

Project Structure

src/
├── index.ts              # Main entry point
├── core/                 # Core infrastructure
│   ├── client.ts         # Extended Discord client
│   ├── config.ts         # Configuration management
│   └── logger.ts         # Logging utility
├── commands/             # Slash commands
│   ├── types.ts          # Command interfaces
│   ├── registry.ts       # Command loading
│   ├── register.ts       # Discord API registration
│   ├── handler.ts        # Command execution
│   └── definitions/      # Command implementations
│       ├── ping.ts
│       ├── spyware.ts
│       ├── sex.ts
│       ├── vemgillarjoel.ts
│       ├── jaggillarjoel.ts
│       └── jaghatarjoel.ts
├── events/               # Discord event handlers
│   ├── types.ts          # Event interfaces
│   ├── register.ts       # Event registration
│   └── handlers/         # Event implementations
│       ├── ready.ts
│       ├── message-create.ts
│       ├── interaction-create.ts
│       └── guild.ts
├── features/             # Feature modules
│   ├── joel/             # Joel AI personality
│   │   ├── responder.ts  # Main response logic
│   │   ├── personalities.ts
│   │   ├── mentions.ts   # Random mention feature
│   │   └── typing.ts     # Typing indicator
│   └── message-logger/   # Message tracking
├── services/             # External services
│   └── ai/               # AI provider abstraction
│       ├── types.ts      # Provider interface
│       ├── replicate.ts  # Replicate implementation
│       └── index.ts      # Service facade
├── database/             # Database layer
│   ├── schema.ts         # Drizzle schema
│   ├── connection.ts     # DB connection
│   ├── migrate.ts        # Migration runner
│   └── repositories/     # Data access
│       ├── guild.repository.ts
│       ├── user.repository.ts
│       ├── message.repository.ts
│       └── memory.repository.ts
└── utils/                # Shared utilities
    ├── discord.ts        # Discord helpers
    ├── random.ts         # Random utilities
    └── time.ts           # Time utilities

Getting Started

Prerequisites

  • Bun runtime
  • Discord bot token
  • Replicate API token

Environment Variables

Create a .env file:

DISCORD_TOKEN=your_discord_token
REPLICATE_API_TOKEN=your_replicate_token

Installation

bun install

Database Setup

# Generate migrations
bun run db:generate

# Run migrations
bun run db:migrate

Running

# Development (with hot reload)
bun run dev

# Production
bun run start

# Build
bun run build

Adding New Features

Adding a Command

  1. Create a new file in src/commands/definitions/:
import { SlashCommandBuilder } from "discord.js";
import type { Command } from "../types";

const command: Command = {
  data: new SlashCommandBuilder()
    .setName("mycommand")
    .setDescription("Description"),
  category: "fun",
  execute: async (interaction) => {
    await interaction.reply("Hello!");
  },
};

export default command;

Commands are auto-loaded from the definitions/ folder.

Adding an Event Handler

  1. Create a new file in src/events/handlers/:
import { Events } from "discord.js";
import type { EventHandler } from "../types";

export const myEventHandler: EventHandler<"eventName"> = {
  name: Events.EventName as "eventName",
  once: false,
  execute: async (client, ...args) => {
    // Handle event
  },
};
  1. Register it in src/events/register.ts

Adding a New AI Provider

  1. Implement the AiProvider interface in src/services/ai/:
import type { AiProvider, AiResponse, AskOptions } from "./types";

export class MyProvider implements AiProvider {
  async health(): Promise<boolean> {
    return true;
  }

  async ask(options: AskOptions): Promise<AiResponse> {
    // Implementation
  }
}
  1. Use it in AiService constructor

Architecture Principles

  • Separation of Concerns: Each module has a single responsibility
  • Dependency Injection: Services can be swapped via interfaces
  • Repository Pattern: Database access through repositories
  • Event-Driven: Discord events are handled by dedicated handlers
  • Feature Modules: Related functionality grouped together