Skip to content

FuseFairy/DiscordBot-GeminiAI

Repository files navigation

DiscordBot-GeminiAI

PyPI - Python Version

Try with Replit Badge

Gemini Demo

demo1

Bard (Gemini web) Demo

demo2

Update

2024/4/28:Support Bard.

2023/2/16:Add Gemini 1.0 Pro model.

Features

Slash command

  • /api_key setting-gemini [choice] [api_key]

  • /gemini conversation [model] [type] [use_prompt] [use_character]

    • Create a thread exclusively for the user to chat with the bot.
      • [model]:Choose AI model.
      • [type]:Choose thread type, private or public.
      • [temperature]:Controls the level of randomness in the output, ranging from highly varied (closer to 1.0) to less surprising (closer to 0.0).
      • [harrassment], [hate_speech], [sexually_explicit], [dangerous_content]:It's Safety Settings, the default is Block some.
  • /cookies setting-bard [choice] [secure_1psid] [secure_1psidts]

    • Can upload own Bard Cookies or delete it.
      • [choice]:delete or set your Bard Cookies.
      • [secure_1psid], [secure_1psidts]:Required Cookie Parameters.
  • /Bard conversation [type]

    • Create a Bard thread exclusively for the user to chat with the bot.
      • [type]:Choose thread type, private or public.

Usage

Install

pip install -r requirements.txt

Discord bot permission

permission

Get Bard Cookies

Warning

It may not be stable.

Important

Since too many people using the same cookies may cause errors, it is recommended to ask the person who wants to use it to upload his/her own cookies.

  • Go to https://gemini.google.com and login with your Google account
  • Press F12 for web inspector, go to Network tab and refresh the page
  • Click any request and copy cookie values of __Secure-1PSID and __Secure-1PSIDTS

.env setting

Rename the file.env.devto.env, then open it and edit it.

DISCORD_BOT_TOKEN=

# Can get from https://makersuite.google.com/app/apikey
GEMINI_API_KEY=

# Setting default Bard cookies
BARD_SECURE_1PSID=
BARD_SECURE_1PSIDTS=

# Allow each commands only use in some channel, if you don't set it, just default to all channels.
# specific channel(s) for `/api_key setting-gemini`
GEMINI_SETTING_CHANNEL_ID=1227670969702754857,1227327094070254857

# specific channel(s) for `/gemini conversation`
GEMINI_CHAT_CHANNEL_ID=1227327094070254857

# specific channel(s) for `/bard conversation`
BARD_CHAT_CHANNEL_ID=

# specific channel(s) for `/cookies setting-bard`
BARD_COOKIES_SETTING_CHANNEL_ID=

# specific channel(s) for `/help`
HELP_CMD_CHANNEL_ID=

Start run your bot.

python3 bot.py

Credits

Contributors

This project exists thanks to all the people who contribute.