This repo is deprecated. See CyberGen49/discord-chatgpt-v2 for the new version.
A Discord bot that allows users to interact with OpenAI's GPT large language and DALL-E image generation models.
Check out the changelog to see what's changed!
You can have a conversation with the bot by sending it a DM or pinging it in a server with a message. In DMs, the bot is only able to remember your previous interaction (question and answer), and there's no conversation history by default in servers.
In both DMs and servers, however, you can reply to any message (from the bot or someone else) and ping the bot with a followup message to use the source message as context. If the reply is to a message from the bot, the input message for that output message will also be included.
/help
: Outputs some help information./stats [user]
: Outputs usage statistics. If a user is provided, their usage stats will be outputted instead./purge
: Purges all of your message entries from the database./fullpurge
: Purges all message entries from the database. Owner only./users
: Manages bot access. Owner only./users allow <user>
: Allows a user to use the bot./users block <user>
: Blocks a user from using the bot./users unset <user>
: Removes a user from the allow/block list./users wipe
: Wipes the allow/block list./users list
: Displays the list of allowed and blocked users.
/dalle
: Generate images from text prompts using DALL-E. Owner only.
These commands can be accessed through the Apps submenu when right-clicking on a message.
Dump response
: When run on a user prompt message or a language model response message sent by the bot, and if the message's data is stored in the database (hasn't been purged), all of the data associated with that interaction will be dumped to JSON and sent as a file. This is mostly for debugging purposes, but can be useful to check how many tokens an interaction used, and if the bot interpreted what it was supposed to.Get conversation link
: If the HTTP server is enabled, you'll get a link to view the selected interaction and its context in your browser. The page nicely renders the conversation's markdown in a chat-like format. This is great for screenshots and conveniently reading long messages that may have been sent as text files.Regenerate response
: When run on a language model response message sent by the bot, and if the message's data is stored in the database (hasn't been purged), the response will be regenerated.
- Download and install Node.js if you don't have it
- Download and install SQLite if you don't have it
- Clone (or download and unzip) the repository and
cd
into it with your terminal - Run
npm install
- Rename
config-template.json
toconfig.json
and open it - Generate an OpenAI secret key and paste it in the
openai.secret
config field- Note: Use of the Chat API isn't free. At the time of writing, it costs $0.002 for every 1000 text tokens. The token count of a request includes any configured starter messages, any conversational context, the user's input, and the model's output.
- Create a new Discord application
- Set its name, description, and picture
- Copy the Application ID and paste it in the
discord.id
config field - Go to the "Bot" tab and create a new bot
- Copy the bot token and paste it in the
discord.token
config field - Scroll down and make sure "Message content intent" is on
- Set your Discord user ID in the
discord.owner_id
config field. - Make any other changes to the config file, then save it.
- Create the message database by running
sqlite3 main.db ".read schema.sql"
.- This is a required step. See Database for details.
- Register the bot's slash and context menu commands by running
node registerCommands.js
- Start the bot with
node bot.js
- If you're on a Unix operating system, run
sh bot.sh
to start the bot and auto-restart it if it crashes.
- If you're on a Unix operating system, run
- Once the bot logs in, an invite URL will be logged. Open it and follow the instructions to add the bot to your server.
- Try it out by DMing or pinging the bot with a question!
As the owner, you're always allowed to use the bot, but with config.public_usage
disabled, nobody else will be able to. If a disallowed user tries using the bot, you'll get a DM with a button to allow them. You can also add users manually with the /users add
command.
Documentation for config.json
has been moved to config-schema.md.
The bot stores every message with its accompanying response in the database we generated during setup.
The database contains a single table, messages
, with the following columns:
time_created
: The timestamp of the interactionuser_id
: The ID of the user who sent the messagechannel_id
: The ID of the channel the message was sent ininput_msg_id
: The ID of the user's messageoutput_msg_id
: The ID of the response messageinput
: The user's inputoutput
: The language model's responsemessages
: The complete messages object for this interaction, as JSONcount_tokens
: The total number of text tokens that this interaction used
This data is used for conversation history and regenerating responses. See the delete_message_days
config option to set up automatic message deletion, and the /fullpurge
slash command to safely wipe all saved messages.