/NPC-chatGPT-discord-bot

Draw NPCs from worldanvil API, feed as prepromts to ChatGPT, turn them into your own discord bot

Primary LanguagePythonGNU General Public License v2.0GPL-2.0

discord-bot for TTRPG NPCs using ChatGPT


Commands

  • /talk [message] Chat with ChatGPT!
  • /locations List locations you can travel to
  • /travel Travel to a location, swapping out the NPCs

Special Features

Mode

  • public mode (default) the bot directly reply on the channel

    image

  • private mode the bot's reply can only be seen by the person who used the command

    image

  • replyall mode the bot will reply to all messages in the channel without using slash commands (/chat will also be unavailable)

    Warning The bot will easily be triggered in replyall mode, which could cause program failures



Installation

Chat

image

Setup

Critical prerequisites to install

  • run pip3 install -r requirements.txt

  • Rename the file .env.example to .env

  • Recommended python version 3.9 +


Step 1: Create a Discord bot

  1. Go to https://discord.com/developers/applications create an application

  2. Build a Discord bot under the application

  3. Get the token from bot setting

    image

  4. Store the token to .env under the DISCORD_BOT_TOKEN

    image
  5. Turn MESSAGE CONTENT INTENT ON

    image

  6. Invite your bot to your server via OAuth2 URL Generator

    image


Note

In Step 2, you only need to complete the authentication process for the model you want to use (it's not necessary to complete all Step 2)

Remember to modify CHAT_MODEL to the default model you want to use in .env file

Step 2: Official API authentication

Geanerate an OpenAI API key

  1. Go to https://beta.openai.com/account/api-keys

  2. Click Create new secret key

    image

  3. Store the SECRET KEY to .env under the OPENAI_API_KEY


Step 3: Run the bot on the desktop

  1. Open a terminal or command prompt

  2. Navigate to the directory where you installed the ChatGPT Discord bot

  3. Run python3 main.py or python main.py to start the bot


Step 3: Run the bot with Docker

  1. Build the Docker image & Run the Docker container docker compose up -d

  2. Inspect whether the bot works well docker logs -t chatgpt-discord-bot

    Stop the bot:

    • docker ps to see the list of running services
    • docker stop <BOT CONTAINER ID> to stop the running bot

Step 4: Deploy bot to Google Compute Engine