Skip to content

voidCaffeLatte/discord-bot

Repository files navigation

Discord Bot

A feature-rich Discord bot written in Rust that brings AI-powered character chat, image generation, and content discovery to your server.

Features

AI Chat (/ai-chat)

Have one-on-one conversations with customizable AI characters. Each character has a name, title, and personality traits defined in a configuration file.

  • Persistent chat history per user per character
  • Relationship system with dynamic likability tracking that influences character responses
  • Web reference citations included in AI responses
  • Daily usage limit per user

AI Conversation (/ai-conversation)

Start a group conversation between two or more AI characters on a given theme and watch them interact with each other in-character.

AI Image Generation (/ai-image)

Generate images from text prompts. Daily usage limit per user.

Random YouTube Video (/random-you-tube-video)

Fetch random videos from a YouTube channel by providing its handle (e.g. @channel). Displays title, view count, duration, publish date, and link.

Random Twitch Clip (/random-twitch-clip)

Fetch random clips from a Twitch streamer by providing their user ID. Displays title, view count, duration, creation date, and link.

Utility

  • /ping — Check bot status
  • /choices — Randomly pick from a list of user-provided options

Architecture

The project follows clean architecture principles with a Cargo workspace of four crates:

src/              Presentation layer (Discord command & modal handlers)
application/      Use cases and gateway/repository trait definitions
domain/           Business models and value objects
infrastructure/   Concrete implementations (API clients, in-memory repositories)
common/           Shared utilities (i18n, caching, collections)

Key design decisions:

  • Dependency inversion — Traits are defined in application/, implementations live in infrastructure/
  • In-memory storage — All state (chat history, activity counters, relationships) is currently held in DashMap as a provisional implementation without transaction management. A migration to an RDBMS with proper transaction support is planned.
  • Localization — All user-facing strings are managed via Fluent (.ftl files) with Japanese as the primary locale

Prerequisites

  • Rust 1.90.0 (pinned via rust-toolchain.toml)
  • API keys for the external services (see Configuration)

Configuration

Environment Variables

Copy the template and fill in your credentials:

cp .env.template .env
Variable Description
DISCORD_TOKEN Discord bot token
DISCORD_BOT_APPLICATION_ID Discord application ID
GEMINI_API_KEY Google Gemini API key
OPENAI_API_KEY OpenAI API key (for image generation)
YOU_TUBE_DATA_API_KEY YouTube Data API v3 key
TWITCH_APP_CLIENT_ID Twitch application client ID
TWITCH_APP_CLIENT_SECRET Twitch application client secret
LOGGING_WEB_HOOK_URL Discord webhook URL for error logging

Character Definition

AI characters are configured in resource/character.toml. Copy the template to get started:

cp resource/character.toml.template resource/character.toml

Each character entry has the following fields:

[[characters]]
name = "Character Name"
title = "Title"
characteristics = ["trait1", "trait2", "trait3"]

Locale Override

You can override any localized string by creating resource/locale/ja-JP.override.ftl. This file is gitignored and will not be committed.

Building & Running

Local

cargo build --release
cargo run

Docker

Production:

docker build -t discord-bot .
docker run --env-file .env discord-bot

Development (with Docker Compose):

docker compose up --build

The development setup mounts the project directory and caches Cargo dependencies in a named volume for faster rebuilds.

Railway

The project includes a .railwayignore for deployment on Railway.

Tech Stack

Category Technology
Language Rust (Edition 2024)
Discord Library Serenity
Async Runtime Tokio
AI Text Generation Google Gemini API
AI Image Generation OpenAI API
HTTP Client reqwest
Data Storage In-memory (DashMap)
Localization Fluent (Japanese)
Logging tracing / tracing-subscriber

This document was generated by Claude Opus 4.6 on Claude Code and reviewed and adjusted by @voidCaffeLatte.

About

A feature-rich Discord bot written in Rust that brings AI-powered character chat, image generation, and content discovery to your server.

Topics

Resources

License

Stars

Watchers

Forks

Contributors