Skip to content

ediziks/BingGPT-Discord-Bot

Repository files navigation

BingGPT-Discord-Bot

BingGPT-Discord-Bot is a Discord bot that can be invited to any Discord servers and be interact with Microsoft's Bing Chat. It's reverse engineered API of Microsoft's Bing Chat which is currently running with GPT-4 and recently started to support Text-to-Image generation

Setup

Requirements

  • python 3.12+
  • A Microsoft Account with early access to https://bing.com/chat (Required)
  • Docker (Optional: Preferred especially on Windows)

Checking access (Required)

  • Install the latest version of Microsoft Edge
  • Alternatively, you can use any browser and set the user-agent to look like you're using Edge (e.g., Mozilla/5.0 (Windows NT 10.0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/109.0.0.0 Safari/537.36 Edg/109.0.1474.0). You can do this easily with an extension like "User-Agent Switcher and Manager" for Chrome and Firefox.
  • Open bing.com/chat and login
  • If you see the chat feature, you are good to go

Getting authentication (Required)

  • Go to the Copilot web page.
  • Open the developer tools in your browser (usually by pressing F12 or right-clicking on the chat dialog and selecting Inspect).
  • Select the Network tab to view all requests sent to Copilot.
  • Write a message on the chat dialog that appears on the web page.
  • Find a request named create?bundleVersion=XYZ and click on it.
  • Scroll down to the requests headers section and copy the entire value after the Cookie: field.
  • Set BING_COOKIES value in the .env file with the copied value. See .example.env file to get the right format.

(Option 1) Installation & Running with Docker

  1. Be sure that Docker and docker-compose are installed on your system

  2. Complete the installation section above up to 3th step (including the 3th)

  3. Build the project

    docker-compose build
  4. Run the application

    • Running in the shell/terminal

      docker-compose up
    • Running in detached mode (similar as a background process)

      docker-compose up -d

(Option 2) Installation & Running with Python

  1. Clone the repo and change directory to repo folder

    git clone https://github.com/ediziks/BingGPT-Discord-Bot.git
    cd BingGPT-Discord-Bot
  2. Place cookies.json file into the main path. See Getting authentication (Required) section above for more information. Also, check example.cookies.json file to see the right path

  3. Set the environment variables (BOT_TOKEN & SERVER_ID) in the .env file. See .example.env file to get the right format and the path. Check creating Discord bot and getting the token for more details about the BOT_TOKEN. And, the SERVER_ID can be simply copied by right clicking the server logo you want to invite the bot, and selecting COPY_ID. See how to get Discord server id for more information.

  4. Install the requirements

    pip install -r requirements.txt
  5. Make bot.py and dcbot.sh files executable

    chmod +x src/bot.py dcbot.sh
  6. The bot can be launched after completing the steps below. There are two alternatives to do so;

    • 1st method: Running the bot with python command in the terminal

      python src/bot.py
    • 2nd method: Running the bot as a background process (Preferred)

      ./dcbot.sh
      • Bot logs can be find under src/bot.log

      • Find the process id with the first command and stop the process by providing the process id in the second command

        ps ax | grep bot.py
        sudo kill -9 <proces_id>

Inviting the Bot

See how to invite a bot to Discord server for more information about the bot invitation. Make sure that the bot permissions look like as in the image below before generating the invitation url

invitation permissions

Usage

Commands

/ask <prompt>      - Ask BingGPT a question
/imagine <prompt>  - Ask BingGPT to imagine visuals
/reset             - Reset the conversation
/hardreset         - Reset the session

Sample Usage

/ask usage

/imagine usage

Known Issues

Currently, the /imagine command doesn't work as expected. Suggestion and PRs are more than welcome.