How fantasybot-red/project_af works
Project type and purpose
• This is a Python-based Discord bot (“AI Fantasy”) that demonstrates how AI can orchestrate and extend bot functionality beyond simple chat.
• It uses a plugin-style architecture (dynamic modules) and integrates with external AI services (via Huggingface) and Discord’s API for real-time interaction.
File structure
Top-level files
• main.py – Bot entry point
• Dockerfile/.env – Deployment and configuration
• requirements.txt – Python dependencies
Directories
• classs/ – Core classes:
– FClient.py (Discord API wrapper)
– AIContext.py (conversation state manager)
– MCPManager.py (SSE-based extension manager)
– Module.py (module interface/loader)
– MusicPlayer.py (audio playback helper)
• modules/ – Pre-built “tools” or functional plugins, e.g.:
– HuggingfaceSupport.py (AI inference calls)
– MusicControl.py (music commands)
– ContextSupport.py (context utilities)
– DiscordExtraHelper.py (extra Discord utilities)
• objs/ – Typed schemas for module arguments (EmbedArgs, Utilitys)
• resources/ – Static prompt files (system_prompt.txt)
Extract insights from the README
• Emphasizes unlimited extension via “MCP SSE” (Server-Sent Events)
• Modules are loaded dynamically and can be managed easily
• Deployment targets: native Python or Docker container
Main components
A. Core application
– main.py
– FClient (Discord event listener/dispatcher)
– AIContext (stateful context manager)
– MCPManager (extension/event bus)
– Module loader (dynamically binds modules)
B. Modules (plugins)
– HuggingfaceSupport (external AI inference)
– MusicControl/MusicPlayer (audio control)
– ContextSupport, DiscordExtraHelper
C. Data models
– objs/ schemas (argument validation, JSON Schema generator)
D. Static resources
– resources/system_prompt.txt
E. External services
– Discord API (gateway + REST)
– Huggingface (or other AI APIs)
F. Deployment
– Docker container or native environment (.env config)
Relationships & data flow
1) Discord → FClient: receives message/event
2) FClient → AIContext: updates conversation state
3) AIContext/MCPManager → Module loader: identify the module to handle the event
4) Module → objs schemas: validate/parse arguments
5) Module (e.g. HuggingfaceSupport) → External AI API → results
6) Module → FClient: send embed/message back to Discord
7) Optional: MusicPlayer → Discord voice channel
Architectural patterns & design principles
• Plugin architecture: Module interface + dynamic discovery
• Event-driven: FClient emits events, MCPManager routes to modules via SSE
• Separation of concerns:
• Networking (FClient)
• Business logic (Modules)
• State management (AIContext)
• Data validation (objs)
• Dependency injection via .env and requirements