This bot is an AI-powered image generation tool designed for Discord servers. It uses Stable Diffusion XL to create high-quality images from text prompts. The bot is built using discord.py. It provides a seamless experience for server members looking to generate creative images directly within Discord.
- Stable Diffusion Integration: Utilizes the Stable Diffusion XL model for generating high-quality images from text prompts.
- GPU Acceleration: Uses CUDA for faster image generation with less wait time.
- Discord Integration: Built using
discord.py, making it easy to integrate and use within Discord servers. - Slash Commands Support: Uses Discord's slash commands for improved user experience.
- Deferred Responses: Handles long-running operations properly with deferred responses.
- Python 3.8+
- pip (Python package installer)
- NVIDIA GPU with CUDA support (see note below for alternatives)
- Discord Bot Token (you can get this from the Discord Developer Portal)
Note for users without a GPU: If you don't have an NVIDIA GPU, you can run this bot on Google Colab or Kaggle notebooks which provide free GPU access. Simply copy the code to a new notebook, install the required dependencies, replace
"YOUR_DISCORD_BOT_TOKEN"with your actual Discord bot token and run it there. Remember that you'll need to keep the notebook running for the bot to stay online.
To use this bot in your Discord server, you'll first need to create a Discord bot through the Discord Developer Portal. Follow these steps to get started:
- Go to the Discord Developer Portal.
- Click on the "New Application" button.
- Enter a name for your application (e.g., "Pixel Flux") and click "Create".
-
Select the bot tab from the menu
-
In the left-hand menu select Installation
-
Scroll down to the Guild Install section
-
Under Scopes, select
botandapplications.commands. -
Under Permissions, select the following permissions:
Attach FilesSend MessagesUse Slash CommandsView Channels
These permissions are essential for the bot to function properly within your server, allowing it to send images and use slash commands.
-
Copy the Install Link open it in a new browser tab.
- Paste the Install Link you copied into your browser and press Enter.
- Choose the server you want to add the bot to from the dropdown list.
- Click "Authorize" and complete the CAPTCHA.
- In the Bot section, under "Token", click on "Reset Token" to generate a new token.
- Copy the token to a secure location; this token is your bot's password and should be kept secret.
- Your bot should be ready to use now.
-
Clone the repository or set up in a notebook:
# Local installation git clone https://github.com/yourusername/discord-image-bot.git cd discord-image-bot # OR for Google Colab/Kaggle # Simply create a new notebook and copy the main.py code there
-
Create a virtual environment:
python -m venv venv
-
Activate the virtual environment:
-
On macOS and Linux:
source venv/bin/activate -
On Windows:
venv\Scripts\activate
-
-
Install the required packages:
pip install discord.py python-dotenv torch diffusers transformers accelerate
-
Add your Discord bot token:
Open the
main.pyfile and replace"YOUR_DISCORD_BOT_TOKEN"with your actual Discord bot token:DISCORD_BOT_TOKEN = "your_actual_token_here"
-
Run the bot:
python main.py
Once the bot is running, it will automatically sync commands with your Discord server. You can begin generating images using the /imagine command.
- Description: Generate an image using Stable Diffusion XL.
- Usage:
/imagine [prompt] - Example:
/imagine a fantasy landscape with mountains and a castle
- Description: Shutdown the bot (admin only).
- Usage:
>>stop
You can modify the following elements in the main.py file:
- Bot Prefix: Change the
command_prefixparameter in the bot initialization (default is>>). - Bot Activity: Modify the
nameparameter in thechange_presencemethod to change the bot's status. - Embed Colors: Change the color value in the embed creation (default is
0x6e38fc). - Model Selection: You can change the Stable Diffusion model by modifying the
from_pretrainedparameter.
Contributions are welcomed from the community. If you'd like to contribute, please fork the repository and submit a pull request with your changes. Make sure to follow the project's coding standards and conventions.