An intelligent, AI-powered Discord bot written in Java using JDA (Java Discord API). The bot functions as an interactive Java programming tutor, leveraging the Groq AI Engine (openai/gpt-oss-120b) to provide concise, structured code explanations, live web search capabilities, dynamic boilerplate class generation, and intelligent local response caching.
- Contextual AI Prompts: Configured with a dedicated tutor system prompt instructing it to respond professionally using precise Java terminology, concise code snippets, and optional coffee emojis (☕).
- Automated Character Safety Limits: Systemic length monitoring keeps all AI outputs below Discord's 2,000-character ceiling to prevent truncation errors.
- Developer Bypass Mode (
/r): An administrative routing mechanism allows the bot owner to toggle off core Java constraints for quick, general-purpose queries.
- Agentic Browser Search: Integrated using Groq's
browser_searchtool suite via raw HTTP payload streams. - Real-time Answers: Dynamically crawls the live web for technical documentation or debugging data when target commands or prefix parameters are passed.
- JSON File Caching: Leverages an
ObjectMapperlayout to store and read visual data directly out ofdata/localcache.json. - Zero API Latency: Intercepts identical incoming prompts, bypassing heavy network requests by retrieving exact matches out of the cache.
- (In progress works only for 1 command for testing)
The bot supports both modern Discord Slash Commands (Guild & User App Installs) and classic chat Prefix Triggers.
| Command | Parameter(s) | Description |
|---|---|---|
/learn |
concepts (Dropdown choice) |
Instantly teaches core programming pillars (Strings, OOP, Recursion, Enums, etc.). |
/query |
query (Text input) |
Asks the Java Tutor AI a customized syntax or conceptual question. |
/askwithsearch |
query (Text input) |
Forces the Groq AI agent to execute a web search before formulating its coding answer. |
/createclass |
name, visibility, mainmethod (Y/N) |
Dynamically prints out a clean, syntax-highlighted Java boilerplate structure inside standard code blocks. |
/java |
username (Text input) |
A clean introduction tool checking runtime installation viability. |
/viewtokens |
None | Diagnostics tool querying total tokens spent ([Prompt, Completion, Total]) on the operational billing loop. |
By typing a message beginning with the q prefix, users can interface with the AI directly from any channel:
q <your question>: Sends a plain request directly through the AI tutoring context pipeline.q /s <your question>: Explicitly fires up the AI's background thread worker to parse abrowser_searchcall over the live web.
- Main Framework: Java Discord API (JDA
v5) utilizingGatewayIntent.MESSAGE_CONTENTandGatewayIntent.GUILD_MESSAGES. - AI Client Architecture: Built on top of
OpenAIOkHttpClientand Java's nativejava.net.http.HttpClienttargetinghttps://groq.com. - Data Serializer: Jackson Core Databind (
ObjectMapper) handling rapid JSON serialization pipelines.
To run the application locally, ensure you export the following secure strings into your host operating system environment:
export DISCORD_TOKEN="your-discord-bot-token-here"
export GROQ_API_KEY="your-groq-platform-api-key-here"