This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
Nidaime Takohachi (二代目タコ八) is a Discord bot written in Rust using the Serenity framework. It provides slash commands and scheduled tasks for Discord servers.
- All user-facing responses and messages should be in Japanese (日本語)
- Error messages shown to Discord users should be in Japanese
- Code comments and internal documentation can remain in English
cargo build # Debug build
cargo build --release # Release build for productioncargo test --all # Run all tests
cargo test <test_name> # Run specific testcargo fmt --all -- --check # Check formatting
cargo fmt --all # Auto-format code
cargo clippy --all -- -D warnings # Lint code with clippycargo check --all # Quick compilation check without producing binaries# First, create config.json from config.example.json and add Discord token
cp config.example.json config.json
# Then run the bot
cargo run- Entry Point:
src/main.rs- Initializes the bot, handles Discord events, and registers slash commands with the guild - Event Handler: Implements Serenity's
EventHandlertrait to process Discord interactions and ready events - Configuration:
src/config.rsloads settings fromconfig.jsonincluding Discord token, guild ID, and channel configurations
All slash commands are in src/commands/:
- Commands are registered in the
readyevent handler inmain.rs - Each command module exports a
runfunction that handles the interaction - Command modules must be added to
src/commands/mod.rswithpub mod <module_name>; - Commands handle their own response creation using Discord's interaction API
Located in src/scheduled_tasks/:
- Task Manager:
mod.rscontainsScheduledTaskManagerthat spawns and manages background tasks - Daily Tasks:
daily_morning_task.rs- Sends scheduled messages to configured channels - Message Cleanup:
delete_message.rs- Handles delayed message deletion - Tasks use
tokio::spawnfor async execution andtokio::time::intervalfor scheduling
src/utils.rs provides helper functions for:
- Date/time operations with Tokyo timezone
- Discord message formatting
- Random selection from lists
- Create new file in
src/commands/(e.g.,mycommand.rs) - Add
pub mod mycommand;tosrc/commands/mod.rs - Implement the command handler with signature:
pub async fn run(ctx: &Context, command: &CommandInteraction) -> Result<(), Box<dyn std::error::Error>> - Add command case to the match statement in
src/main.rs::interaction_create() - Register the command in
src/main.rs::ready()usingCreateCommand::new()
- Create new file in
src/scheduled_tasks/ - Implement task with async function
- Add task initialization to
ScheduledTaskManager::new()insrc/scheduled_tasks/mod.rs - Use
tokio::spawnandtokio::time::intervalfor scheduling
The bot requires a config.json file with:
discord_token: Bot authentication tokenguild_id: Discord server ID for command registrationmorning_greeting_channel_id: Channel for daily messagesadmin_channel_id: Channel for admin notifications- Additional feature-specific settings
For production deployment, use systemd service:
- Build with
cargo build --release - Follow
SYSTEMD_SETUP.mdfor service configuration - Binary location:
/opt/takohachi/nidaime-takohachi - Config location:
/opt/takohachi/config.json - Service management:
sudo systemctl {start|stop|restart|status} takohachi