Discord AI Bot
Python + discord.py bot that converts natural language requests into structured actions using OpenAI tool-calling. It can answer questions, fetch quick web snippets, or trigger local scripts like test runs directly from chat.

What it does
- •Natural-language command `!ask` that routes to OpenAI function-calling for structured JSON intents.
- •Tool calls handle web search and weather lookups before returning concise answers into Discord.
- •Script runner bridges intents to local automation (tests, log checks) and streams stdout back to chat.
- •Guardrails for missing API keys or malformed JSON so the bot explains errors instead of failing silently.
Stack & integration
Discord: commands via discord.py with message content intent enabled.
OpenAI: JSON-only system prompt, function/tool calls, and graceful error surfacing.
Automation: Subprocess runner for tests/log scripts; easy to extend with new actions.
Reliability: Structured parsing, weather/search shortcuts, and dotenv-loaded secrets.
Request → Action pipeline
- 1User types `!ask <request>`.
- 2OpenAI prompt constrains the model to emit JSON actions (run_test, check_logs, answer, unknown).
- 3Optional DuckDuckGo + weather fetch when the model requests web_search tool output.
- 4Script runner executes the requested action and returns trimmed output to the Discord channel.