MCPcopy Index your code
hub / github.com/EnArvy/Discord-Gemini-Chatbot

github.com/EnArvy/Discord-Gemini-Chatbot @main

Chat with this repo
repository ↗ · DeepWiki ↗ · + Follow
39 symbols 139 edges 7 files 38 documented · 97% updated 6mo ago★ 33
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

Discord Bot to interact with Gemini API as ChatBot

Preview

Preview

Inspiration - https://github.com/Echoshard/Gemini_Discordbot

This bot acts as a Chatbot. It uses Google's Gemini API which is free for upto 60 calls/min as of Jan 2023.

Supports images, audio, documents and Gemini 1.5 completely!

Usage

The bot can be talked to by mentioning it or DMing it.

Each channel/thread has it's own context and can be erased by using /forget.

Additionally, a persona can be specified while making it forget history.

Due to API restrictions, the bot cannot remember image interactions.

Requirements

Get a Google Gemini api key from ai.google.dev

Make a discord bot at discord.com/developers/applications

Running

Clone repository

Install all dependencies as specified in requirements.txt

Create a .env file and add GOOGLE_AI_KEY and DISCORD_BOT_TOKEN in as specified in .env.development file

Run as python main.py

Customization

Optionally, you can configure the bot as follows using settings.py:

Add custom initial conversation for every chat by editing the BOT_TEMPLATE variable as follows:

BOT_TEMPLATE = [
    {'role':'user','parts': ["Hi!"]},
    {'role':'model','parts': ["Hello! I am a Discord bot!"]},
    {'role':'user','parts': ["Please give short and concise answers!"]},
    {'role':'model','parts': ["I will try my best!"]},
]

Change content safety settings as follows:

SAFETY_SETTINGS = [
    {"category": "HARM_CATEGORY_HARASSMENT", "threshold": "BLOCK_NONE"},
    {"category": "HARM_CATEGORY_HATE_SPEECH", "threshold": "BLOCK_NONE"},
    {"category": "HARM_CATEGORY_SEXUALLY_EXPLICIT", "threshold": "BLOCK_NONE"},
    {"category": "HARM_CATEGORY_DANGEROUS_CONTENT", "threshold": "BLOCK_NONE"}
]

Change AI generation parameters using the variables TEXT_GENERATION_CONFIG and IMAGE_GENERATION_CONFIG

Misc

Error logs are stored in the errors.log file created at runtime.

Chat data is stored between bot runs using shelve.

Core symbols most depended-on inside this repo

load_tracked_threads
called by 2
storage.py
save_chat_history
called by 2
storage.py
save
called by 2
commands.py
get_history
called by 2
ai_service.py
get_attachment_data
called by 2
attachments.py
load_chat_history
called by 1
storage.py
save_tracked_threads
called by 1
storage.py
delete_chat_history
called by 1
storage.py

Shape

Method 22
Function 12
Class 4
Route 1

Languages

Python100%

Modules by API surface

commands.py10 symbols
main.py8 symbols
storage.py7 symbols
ai_service.py7 symbols
message_handler.py5 symbols
attachments.py2 symbols

For agents

$ claude mcp add Discord-Gemini-Chatbot \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact