Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Discord Image Generation Bot powered by Stable Diffusion XL. Create stunning AI-generated images directly in your Discord server with simple slash commands. No complex setup required - just add your token and start creating!

Notifications You must be signed in to change notification settings

FiziQaiser/Discord-Image-Generation-Bot

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 

Repository files navigation

Discord Image Generation Bot

Bot Status Python Version Stable Diffusion Discord.py

Table of Contents

Introduction

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.

Features

  • 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.

Setup

Prerequisites

  • 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.

Creating a Discord Bot

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:

Step 1: Create a New Application

  1. Go to the Discord Developer Portal.
  2. Click on the "New Application" button.
  3. Enter a name for your application (e.g., "Pixel Flux") and click "Create".

Step 2: Configure Bot Permissions

  1. Select the bot tab from the menu

  2. In the left-hand menu select Installation

  3. Scroll down to the Guild Install section

  4. Under Scopes, select bot and applications.commands.

  5. Under Permissions, select the following permissions:

    • Attach Files
    • Send Messages
    • Use Slash Commands
    • View Channels

    These permissions are essential for the bot to function properly within your server, allowing it to send images and use slash commands.

  6. Copy the Install Link open it in a new browser tab.

Step 3: Invite the Bot to Your Server

  1. Paste the Install Link you copied into your browser and press Enter.
  2. Choose the server you want to add the bot to from the dropdown list.
  3. Click "Authorize" and complete the CAPTCHA.

Step 4: Retrieve Your Bot Token

  1. In the Bot section, under "Token", click on "Reset Token" to generate a new token.
  2. Copy the token to a secure location; this token is your bot's password and should be kept secret.
  3. Your bot should be ready to use now.

Installation

  1. 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
  2. Create a virtual environment:

    python -m venv venv
  3. Activate the virtual environment:

    • On macOS and Linux:

      source venv/bin/activate
    • On Windows:

      venv\Scripts\activate
  4. Install the required packages:

    pip install discord.py python-dotenv torch diffusers transformers accelerate
  5. Add your Discord bot token:

    Open the main.py file and replace "YOUR_DISCORD_BOT_TOKEN" with your actual Discord bot token:

    DISCORD_BOT_TOKEN = "your_actual_token_here"
  6. Run the bot:

    python main.py

Usage

Once the bot is running, it will automatically sync commands with your Discord server. You can begin generating images using the /imagine command.

Commands

1. /imagine
  • Description: Generate an image using Stable Diffusion XL.
  • Usage: /imagine [prompt]
  • Example: /imagine a fantasy landscape with mountains and a castle
2. >>stop
  • Description: Shutdown the bot (admin only).
  • Usage: >>stop

Configuration

You can modify the following elements in the main.py file:

  • Bot Prefix: Change the command_prefix parameter in the bot initialization (default is >>).
  • Bot Activity: Modify the name parameter in the change_presence method 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_pretrained parameter.

Contributing

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.

About

Discord Image Generation Bot powered by Stable Diffusion XL. Create stunning AI-generated images directly in your Discord server with simple slash commands. No complex setup required - just add your token and start creating!

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages