Giter Site home page Giter Site logo

electronic-mango / openai-discord-bot Goto Github PK

View Code? Open in Web Editor NEW
1.0 2.0 0.0 88 KB

Discord bot for your ChatGPT needs.

License: GNU General Public License v3.0

Dockerfile 2.24% Python 97.76%
bot chatgpt discord hikari-lightbulb hikari-py openai python python3

openai-discord-bot's Introduction

Simple OpenAI text model Discord bot

A simple and unofficial Discord bot wrapping OpenAI API text models (like ChatGPT), build with hikari and lightbulb!

Bot works on servers for everyone, it will respond to DMs only for bot owner.

Requirements

This bot was built with Python 3.11, hikari, lightbulb and openai-python. Full list of Python requirements is in the requirements.txt file, you can use it to install all of them.

Bot permissions

Message content

This bot requires message content privileged gateway intent to function correctly. This is required as bot responds to all messages in a given channel.

You can enable this content for the whole bot in Discord Developer Portal and specific bot settings.

Currently, bot won't even start without this privileged intent enabled.

Sending text messages

Bot also requires Send Messages in Text permissions, as it responds with regular messages.

Configuration

Configuration is done through a .env file. You can copy example file .env.example as .env and fill required parameters.

cp .env.example .env

Discord bot

Only required parameter is a bot token

BOT_TOKEN='<your secret bot token>'

You can optionally configure max send message length, by default length of 2000 is used:

MAX_MESSAGE_LENGTH=<custom max message length>

If message send by the bot exceeds this value it's split into multiple messages. 2000 is max message length for Discord bots, thus it's used by default.

You can also optionally specify file in which all target channels for start command can be stored:

SOURCES_PERSISTENCE_FILE='<path to basic persistence file>'

Bot will store all channel IDs where automatic responding is configured in this file.

It won't store full message conversation. After bot is restarted (if the specified file still exists and wasn't modified) it will keep responding in previously configured channels, however it won't be able to "pick up" the conversation.

OpenAI API

One required parameter is API key.

OPENAI_TOKEN='<your secret API key>'

Through .env you can also configure other parameters:

  • OPENAI_MODEL - which model to use (gpt-3.5-turbo is used by default)
  • OPENAI_SYSTEM_MESSAGE - system message
  • OPENAI_CONTEXT_LIMIT - how many messages will be kept in the context aside from prompt, all messages will be kept if empty
  • OPENAI_INITIAL_MESSAGE - additional message added after system message to all conversations, can be empty for no additional messages
  • OPENAI_LOG - log level of OpenAI API, either debug or info, can be empty for no additional logging configuration

Note that gpt-3.5-turbo doesn't pay strong attention to system message, so changing it might not provide significant changes to responses. You can use OPENAI_INITIAL_MESSAGE to tweak initial behaviour of the model.

OPENAI_MODEL='gpt-3.5-turbo'
OPENAI_SYSTEM_MESSAGE='You are a helpful assistant.'
OPENAI_CONTEXT_LIMIT=1000
OPENAI_INITIAL_MESSAGE='You are a helpful assistant acting like 18th century butler,'
OPENAI_LOG='info'

Commands

All commands work on servers for everyone and in DMs for bot owner.

  • /start - start responding to all messages in current channel
  • /quiet_start - start responding to all messages in current channel without notifying other users
  • /stop - stop responding to messages
  • /quiet_stop - stop responding to messages without notifying other users
  • /restart - reset current conversation and removes all context, other than system message
  • /ask - ask for specific prompt, can be used in channels which aren't actively monitored
  • ask - message command, can use specified message as prompt
  • /prompt set <prompt text> - set custom prompt for this channel
  • /prompt reset - clear custom prompt for this channel
  • /prompt remove - remove all prompts, including ones from bot configuration file
  • /prompt get - get custom prompt, won't return prompt from configuration file to avoid leaking configuration data to users

Running the bot

You can run the bot from the source code directly, or in a Docker container.

From source code

  1. Create a Discord bot
  2. Create OpenAI API key
  3. Install all packages from requirements.txt
  4. Fill .env file
  5. Run main.py file with Python

Docker

  1. Create a Discord bot
  2. Create OpenAI API key
  3. Fill .env file
  4. Run docker compose up -d --build in terminal

Note that .env file is used only for loading environment variables into Docker container through compose. The file itself isn't added to the container.

When using Docker the bot will automatically store channel IDs for purposes of start command in persistence file located in project root.

Disclaimer

This bot is in no way affiliated, associated, authorized, endorsed by, or in any way officially connected with OpenAI. This is an independent and unofficial project. Use at your own risk.

openai-discord-bot's People

Contributors

electronic-mango avatar

Stargazers

 avatar

Watchers

 avatar  avatar

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.