This project is a Discord bot that integrates with AI models through the OpenRouter API. The bot responds to messages in your Discord server using advanced language models, providing natural and context-aware responses. It supports text interactions and image analysis, making it a versatile tool for various Discord communities.
- AI-powered responses using models from OpenRouter
- Image analysis capabilities
- Conversation context management
- Queue system for handling multiple requests
- Rate limiting and error handling
- Support for multiple AI models
- Python 3.7 or higher
- A Discord account and a server where you have permissions to add bots
- An OpenRouter account and API key
-
Clone this repository or download the source code.
-
Install the required Python packages:
pip install -r requirements.txt -
Create a
.envfile in the project root and add the following:OPENROUTER_API_KEY=your_openrouter_api_key_here DISCORD_BOT_TOKEN=your_discord_bot_token_here -
Replace
your_openrouter_api_key_herewith your OpenRouter API key andyour_discord_bot_token_herewith your Discord bot token.
- Go to the Discord Developer Portal.
- Click "New Application" and give your bot a name.
- Go to the "Bot" section and click "Add Bot".
- Under "Token", click "Copy" to copy your bot token (use this in your
.envfile). - Enable the "Message Content Intent" under "Privileged Gateway Intents".
- Go to "OAuth2" > "URL Generator", select "bot" under scopes, and choose necessary permissions.
- Use the generated URL to invite the bot to your server.
-
Run the bot:
python DC.py -
In your Discord server, use the command prefix
!aifollowed by your message to interact with the bot. For example:!ai What's the weather like today? -
To analyze an image, attach an image to your message along with the
!aicommand.
- You can change the AI model by modifying the
OPENROUTER_MODELvariable inDC.py. - Adjust the
MAX_CONTEXT_MESSAGESandCONTEXT_EXPIRATIONvariables to change how conversation context is managed. - Modify the
MAX_QUEUE_SIZEto change the number of requests the bot can handle simultaneously.
Contributions to improve the bot are welcome. Please feel free to submit pull requests or open issues to suggest improvements or report bugs.
This project is open-source and available under the MIT License.
This bot uses AI models that may produce content that doesn't reflect real-world facts or opinions. Always verify important information from reliable sources.