This project integrates an AI chatbot into a Discord bot using OpenAI's GPT-3.5-Turbo model. Users can interact with the bot by asking questions, and the bot responds using the OpenAI API.
- Slash command
/askto ask the AI bot a question. - Rate-limiting and token count management to stay within OpenAI's usage limits.
- Error handling and exponential backoff for rate-limited requests.
- Java Development Kit (JDK) 21
- Maven for dependency management
- OpenAI API Key
- Discord Bot Token
git clone <repository-url>
cd <repository-directory>Create a .env file in the root of your project and add your API keys: OPENAI_API_KEY=your_openai_api_key DISCORD_BOT_TOKEN=your_discord_bot_token
Replace your_openai_api_key and your_discord_bot_token with your actual OpenAI API key and Discord bot token.
This project uses Maven for dependency management and building. To build the project, navigate to the project directory and run:
mvn clean installAfter building the project, you can run the bot using the following command:
java -jar target/AI-Bot-1.0-SNAPSHOT.jarReplace AI-Bot-1.0-SNAPSHOT.jar with the name of the JAR file created during the build process if it's different.
src/main/java/com/github/spacemex/api: Contains the OpenAI client for interacting with OpenAI's API.src/main/java/com/github/spacemex/util: Contains utility classes and the command manager for processing Discord commands.
Once the bot is running, you can ask questions using the slash command /ask in your Discord server. The bot will respond with an answer generated by OpenAI's GPT-3.5-Turbo model.
To integrate OpenAI with a Discord bot, you need to...
Contributions are welcome! Please fork this repository and submit a pull request for review.
This project is licensed under the MIT License. See the LICENSE file for more details.