This is a simple Discord bot that uses OpenAI's GPT language model to chat with users. It is built with Node.js and the Discord.js library.
- Node.js (v14 or higher)
- A Discord bot token (get one here)
- Clone the repository or download the source code
- Install dependencies with
npm install
- Create a
config.json
file based on theconfig-example.json
file and add your Discord bot token and OpenAI API key - Start the bot with node chatgpt.js`
The bot listens for the /chat
command followed by a message from the user. It then sends the message to the OpenAI API and replies to the user with the response.
Example: /chat How are you doing today?
- Go to your Discord developer portal and select your application.
- Select "OAuth2" from the sidebar.
- Under "Scopes," select "bot."
- Under "Bot Permissions," select all permissions that the bot requires. In this case, it requires the "Send Messages" permission under "Text Permissions."
- Scroll back up and copy the generated OAuth2 URL.
- Open the OAuth2 URL in your browser and select the server you want to add the bot to.
- Follow the instructions to authorize the bot and add it to your server.
Note: Make sure you have the "Manage Server" permission on the server you're adding the bot to.