A lightweight Discord bot that uses Google Gemini API to provide AI-powered responses, supports a backend-only character persona, conversation history, and repetition detection.
- Responds to @mentions in your Discord server
- Uses Google Gemini 2.0 API for AI responses (with updated integration)
- Per-user system prompts: Easily define custom Sally personalities for specific users by adding a text file in the
prompts/directory named after their Discord user ID. The default persona is used if no custom file is found. - Owner-only ignore commands:
!ignore <discord_id>and!clearignoresallow the bot owner to ignore or unignore users at runtime. - Backend-only character persona (cannot be changed by Discord users)
- Remembers recent conversation history per channel
- Avoids repeating the same response to similar questions
- Repeated message catch: If a user repeats the same message, Sally responds with a generic roast instead of calling the API.
- 'Are you sure' catch: Instantly replies with a generic, in-character response if "are you sure" appears anywhere in the message, skipping the API call.
- Install dependencies
pip install -r requirements.txt
- Add your API keys and tokens
- Create a file named
.envin the project folder (see example below). - Add your secrets (do not commit this file to GitHub):
DISCORD_TOKEN=your_discord_token_here GEMINI_API_KEY=your_gemini_api_key_here OWNER_ID=your_discord_user_id_here
OWNER_IDis the Discord user ID of the bot owner. This can be used to restrict certain commands or actions to only the owner, or for bot identification purposes.- The
.envfile is already in.gitignoreand will not be tracked by git.
- Create a file named
- User history:
- The file
user_history.jsonis used to store persistent, per-user conversation history. This history provides context to the AI for more relevant responses and is loaded when the bot starts. - If you want to preserve or carry over user history to another device, manually copy your
user_history.jsonfile to the new environment. - If starting fresh, the bot will create a new, empty
user_history.jsonautomatically. - Separately, short-term conversation history for repetition detection within each channel is stored in memory and resets when the bot restarts.
- The file
- Edit the character system prompt or add per-user prompts
- To change the default Sally persona, open
system_prompt.txtand edit as desired. - To assign a custom persona to a specific user, create a file in the
prompts/directory named<discord_user_id>.txtand write their unique Sally prompt. - The bot will automatically use a user's custom prompt if present; otherwise, it falls back to the default.
- The system prompt is automatically prepended to user messages for Gemini 2.0 API compatibility (no 'system' role is used).
- To change the default Sally persona, open
- Run the bot
python bot.py
- Mention the bot in any channel to get a response.
- The backend system prompt (in
system_prompt.txt) defines Sally's default personality. For specific users, a custom prompt can be added in theprompts/directory. - Only backend maintainers can change prompts by editing files; Discord users cannot change Sally's persona from within Discord.
- Owner-only commands:
!ignore <discord_id>: Add a user to the ignore list. Ignored users always get a generic Sally response and no Gemini API call is made.!clearignores: Clear the ignore list and restore normal behavior.
Note:
- Per-user conversation history is stored in
user_history.jsonand loaded on startup. Short-term channel-based history for repetition checks is in-memory and resets on restart. - The character system prompt is stored in
system_prompt.txt(or per-user files inprompts/) and loaded on startup.