GithubHelp home page GithubHelp logo

josantonius / chatgpt-discord-bot Goto Github PK

View Code? Open in Web Editor NEW
5.0 2.0 1.0 27 KB

A bot designed for a small Discord channel among friends. This bot allows assigning a distinct personality to each user and maintaining the context of previous questions and answers. It also has the ability to view and understand images, so that one or more images can be attached to the message. It's powered by OpenAI's ChatGPT models.

Home Page: https://josantonius.dev

License: MIT License

Python 100.00%
chatgpt chatgpt-bot discord discord-bot openapi

chatgpt-discord-bot's Introduction

ChatGPT Discord Bot

License

A bot designed for a small Discord channel among friends. This bot allows assigning a distinct personality to each user and maintaining the context of previous questions and answers. It also has the ability to view and understand images, so that one or more images can be attached to the message. It's powered by OpenAI's ChatGPT models.

Requirements

  • Python 3.6 or above.
  • An OpenAI API key.
  • A Discord bot token.

Installation

Clone this repository:

git clone https://github.com/josantonius/chatgpt-discord-bot.git

Install the required Python packages:

pip install discord.py openai

Configuration

Create a config.json file in the root directory of the bot. This is an example of how the configuration file should look like:

{
    "model": "gpt-4o",
    "memory_characters": 120000,
    "history_refresh_interval": 900,
    "openai_api_key": "<Your OpenAI API key>",
    "discord_token": "<Your Discord Bot Token>",
    "presence": "The Lounge",
    "context": [
        {
            "discord_name": "Evellyne",
            "personality": "Evelyn is a seasoned data scientist. Interact in a polite and..."
        },
        {
            "discord_name": "Sammy",
            "personality": "Sam is a popular YouTube vlogger. Communicate in a cheerful and..."
        },
        {
            "discord_name": "Morgan",
            "personality": "Morgan is an NFT enthusiast. Respond to them with skepticism..."
        }
    ],
    "global_personality": "Maintain a cordial demeanor.",
    "system_context": "You are an admin of a Discord channel assigned by Evelyn.",
    "error_message": "Words fail me at the moment :/"
}

memory_characters are the number of characters that the bot will remember from previous messages. This value should not exceed the maximum number of tokens allowed by the model you are using.

history_refresh_interval is the interval in seconds at which the chat context is refreshed.

Replace <Your OpenAI API key> and <Your Discord Bot Token> with your actual OpenAI API key and Discord bot token respectively.

Each user in your Discord channel should have an entry in the context array with their Discord username and the personality you want the bot to use when interacting with them. If a user does not have a specific entry, the bot will use the global_personality.

The original names of Discord users are not sent to ChatGPT for privacy. Instead, the bot uses the discord_name field to identify users.

The system_context is the initial context of the conversation with the bot.

Running the Bot

Once you have set up the configuration file, you can run the bot using Python:

python bot.py

Your bot should now be running and ready to interact with in your Discord server!

Commands

The bot is summoned by mentioning it at the start of the message. For example:

@ChatGPT How are you?

It also has the ability to view and understand images, so that one or more images can be attached to the message.

Logging

The bot logs all messages and API calls for debugging purposes. The log is printed to the console.

TODO

  • Add new feature
  • Add tests
  • Improve documentation

Changelog

Detailed changes for each release are documented in the release notes.

Contribution

Please make sure to read the Contributing Guide, before making a pull request, start a discussion or report a issue.

Thanks to all contributors! โค๏ธ

Sponsor

If this project helps you to reduce your development time, you can sponsor me to support my open source work ๐Ÿ˜Š

License

This repository is licensed under the MIT License.

Copyright ยฉ 2023-present, Josantonius

chatgpt-discord-bot's People

Contributors

josantonius avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

julienr78

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.