Code Monkey home page Code Monkey logo

bestfriend's Introduction

Please read!

For any problems running this specific bot: Discord Project Post

For general OpenAI API problems or questions: Discord API Discussions

For bugs in the template code: create an Issue

For feature requests: this repo is not accepting feature requests, you can discuss potential features in Discord Project Post

For PRs: only bug fix PRs wil be accepted. If you are implementing a new feature, please fork this repo.

Thank you!


GPT Discord Bot

Example Discord bot written in Python that uses the chat completions API to have conversations with the gpt-3.5-turbo model, and the moderations API to filter the messages.

This bot uses the OpenAI Python Library and discord.py.

Features

  • /chat starts a public thread, with a message argument which is the first user message passed to the bot. You can optionally also adjust the temperature and max_tokens parameters.
  • The model will generate a reply for every user message in any threads started with /chat
  • The entire thread will be passed to the model for each request, so the model will remember previous messages in the thread
  • when the context limit is reached, or a max message count is reached in the thread, bot will close the thread
  • you can customize the bot instructions by modifying config.yaml
  • you can change the model, the default value is gpt-3.5-turbo

Setup

  1. Copy .env.example to .env and start filling in the values as detailed below
  2. Go to https://beta.openai.com/account/api-keys, create a new API key, and fill in OPENAI_API_KEY
  3. Create your own Discord application at https://discord.com/developers/applications
  4. Go to the Bot tab and click "Add Bot"
    • Click "Reset Token" and fill in DISCORD_BOT_TOKEN
    • Disable "Public Bot" unless you want your bot to be visible to everyone
    • Enable "Message Content Intent" under "Privileged Gateway Intents"
  5. Go to the OAuth2 tab, copy your "Client ID", and fill in DISCORD_CLIENT_ID
  6. Copy the ID the server you want to allow your bot to be used in by right clicking the server icon and clicking "Copy ID". Fill in ALLOWED_SERVER_IDS. If you want to allow multiple servers, separate the IDs by "," like server_id_1,server_id_2
  7. Install dependencies and run the bot
    pip install -r requirements.txt
    python -m src.main
    
    You should see an invite URL in the console. Copy and paste it into your browser to add the bot to your server. Note: make sure you are using Python 3.9+ (check with python --version)

Optional configuration

  1. If you want moderation messages, create and copy the channel id for each server that you want the moderation messages to send to in SERVER_TO_MODERATION_CHANNEL. This should be of the format: server_id:channel_id,server_id_2:channel_id_2
  2. If you want to change the personality of the bot, go to src/config.yaml and edit the instructions
  3. If you want to change the moderation settings for which messages get flagged or blocked, edit the values in src/constants.py. A higher value means less chance of it triggering, with 1.0 being no moderation at all for that category.

FAQ

Why isn't my bot responding to commands?

Ensure that the channels your bots have access to allow the bot to have these permissions.

  • Send Messages
  • Send Messages in Threads
  • Create Public Threads
  • Manage Messages (only for moderation to delete blocked messages)
  • Manage Threads
  • Read Message History
  • Use Application Commands

bestfriend's People

Contributors

yufeig avatar kav-k avatar veylkh 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.