Skip to content

hmes98318/ChatGPT-Discord-Bot

Repository files navigation

ChatGPT-Discord-Bot

GitHub

A Discord chatbot powered by OpenAI's GPT3.5 model and DALL·E image generation model.

Installation

Precondition

  • TypeScript 4.9
  • Node.js v18

Clone the repository

git clone https://github.com/hmes98318/ChatGPT-Discord-Bot.git

or click here to download

Install the dependencies

install all the dependencies from package.json

npm install

Configure environment

.env

PREFIX = "?"
PLAYING = "?help"
TOKEN = "discord_bot_token"
OPENAI_API_TOKEN = "openai_api_token"

# Text chat
OPENAI_API_MODEL = "gpt-3.5-turbo"
BOT_MAX_REPLY_COUNT = 5
BOT_MAX_TEXT_LENGTH = 1000

# Image generation
OPENAI_API_IMAGE_SIZE = "512x512"
OPENAI_API_IMAGE_COUNT = 1
OPENAI_API_IMAGE_RESPONSE_FORMAT = "url"

# API setup
OPENAI_API_USER = "user"
OPENAI_API_MAX_TOKEN = 1000
OPENAI_API_TIMEOUT = 30
Detailed description

OPENAI_API_MODEL: GPT models list https://beta.openai.com/docs/models.
MAX_REPLY_COUNT: Number of previous messages the bot remembers.
MAX_TEXT_LENGTH: Maximum send message length.

OPENAI_API_IMAGE_SIZE: Generate image size. [ 1024x1024 | 256x256 | 512x512 ]
OPENAI_API_IMAGE_COUNT: Number of generated images.
OPENAI_API_IMAGE_RESPONSE_FORMAT: The format in which the generated images are returned.

OPENAI_API_USER : Chat Completion Request Message Role Enum. [ user | system | assistant ]
OPENAI_API_MAX_TOKEN: Bot maximum reply message length.
OPENAI_TIMEOUT: Reply message maximum waiting timeout.

Get the OpenAI api key :

Running the script

Production

npm run start

Development

npm run dev

Usage

Text Commands:

  • ?chat <message> : chat with the ChatAI Bot
  • ?img <prompt> : Generate AI images
  • ?help : get command help

Slash Commands:

  • /chat
  • /image
  • /help

NOTE: The remember effect is only useful when using Text Commands Reply.
You have to reply to the previous message to trigger but it will increase the consumption of tokens.

Example

Text chat

img1

img2

Image generation

img4

Remember previous few one message example

img3