imageGenSD is a multi-purpose Discord bot. It creates character images and profiles in a gacha-like manner for users to interact with and enjoy.
imageGenSD also contains a Stable-Diffusion wrapper written in Python. It uses Discord.py to listen for user requests and pass the commands to a Stable-Diffusion backend for processing, posting the results to the channel as requested.
This project does not contain Stable-Diffusion. Be sure you've downloaded the webui project and the desired weights. Rentry.org has an excellent walkthrough for the newcomer.
Note that various Stable Diffusion training sets can generate a variety of images, heavily influenced by the weight source. Be prepared for the AI engine to return NSFW content if you're not careful. There effectively nothing the bot can do to prevent this as it's a byproduct of the ML training set.
- Python 3.11.2 or later
- Stable Diffusion UI 1.4 or later
- Discord.py 2.2.2 or later
- Mariadb 10.11 or later
- Mariadb python connector 1.1.9 or later
- coverage.py 7.4.3 or later
Many of these dependencies are inherited from the Stable-Diffusion project or are required to interface with a database.
All files in this repo fall under the GPLv3. See the individual projects for their respective licenses.
This project has been tested on:
- Windows 10
- Ubuntu 22
- Debian 12
- MacOS 14
Note: setup varies by OS.
- Install Stable Diffusion.
- Download any models, VAEs, and other extensions you want to use.
- Modify
webui-user.sh
orwebui-user.bat
to include the command line argument--api
.
- Install MariaDB (This must be done first on some OS's).
- Perform any initial MariaDB setup, if required (e.g.
mysql_secure_installation
). - Ensure your MariaDB is initialized to acecpt large packets, i.e.:
- Set
max_allowed_packet=4G
inmy.ini
ormy.cnf
.
- Set
- Perform any initial MariaDB setup, if required (e.g.
- Install all pip modules (in a venv if using modern versions of Python).
- Note that some OS's require manual install of additional elements, such as:
libmariadb3 libmariadb-dev
on Linux.Applications/Python <version> Profile.command
on MacOS.
- Note that some OS's require manual install of additional elements, such as:
- Initialize the MariaDB database with the commands:
CREATE DATABASE IGSD;
CREATE USER IF NOT EXISTS 'IGSD_Bot'@'%' IDENTIFIED BY 'password';
GRANT ALL PRIVILEGES ON IGSD.* TO 'IGSD_Bot'@'%';
- Enter your Discord Bot's static login token into the
src/config/credentials.json
file.- DO NOT commit this value to a public repo!
<path to venv bin folder>python imageGenSD.py
The bot will run in the terminal until killed with a Ctrl+C
or similar.
<path to venv bin folder>python RunUnitTests.py
Test results are stored in covhtml
located at the top-level directory.
mariadb -u root -p < table_update.sql
You will need to use the password defined in the project's config
file.
Upgrade scripts can be found under the update_scripts
folder and must be run
in numeric order (e.g. 3.8
before 3.9
).
Note: All command require a user to have at least slash command privileges.
/about
- Gives basic bot information.
Displays some basic information about the bot, including an invite link.
assign {tier} {type}
- Assign at least one Character Profile to the given type of work.
Allows a user to fill a given work type with as many character profiles as is is allowed by their economy settings. Multiple characters can be assigned in a single action. Selections will not be preserved across drop-down pages if a user tries to both select a profile and navigate to a new page in the same action.
type
is a list of different actions that can be assigned workers. Defaults
to the Dungeon Exploration Team type.
tier
indicates which tier should be managed, with 1 as the lowest and 6 as
the highest. The command defaults to tier 1 if no selection is provided.
/generate {cfg_scale} {height} {negative_prompt} {prompt} {randomize} {sampler} {seed} {steps} {tag_cnt} {width}
- Generate an image
Provides a user-supplied job to the webui back-end. All parameters are optional and defaults are provided. All inputs are limited to reasonable values (or the constraints of Discord/Stable Diffusion).
Setting Randomize to 'true' causes the system to select a random number of tags to append to the prompt (or a specific number if 'tag_cnt' is specified). This can be combined with a user-supplied prompt.
/hello
- Echo the author's name in chat.
Confirms the bot has the bare minimum capability for interacting in the Guild.
/listprofiles {name} {rarity} {user}
- Show all profiles associated with a specific Discord account.
Provides a paginated menu of profile names and IDs associated with a Discord account (and stored in the database). If none, it encourages the user to create a profile with an appropriate command.
Pages can be navigated with the provided buttons and will be eventually disabled after a timeout.
If name
is specified, the resulting paginated menu will only contain
profiles whose name at least partially matches the specified name
If rarity
is specified, the resulting paginated menu will only contain
profiles that are of the matching rarity.
Not specifying user
will cause the menu to show the author's profiles.
Only the command author is allowed to use the navigation buttons.
remove {type} {tier}
- Remove at least one Character Profile from a given type of work.
Allows a user to free work slots of the given type from as many character profiles as is allowed by their economy settings. Multiple characters can be removed in a single action.
type
is a list of different actions that can be assigned workers. Defaults
to the Dungeon Exploration Team type.
tier
indicates which tier should be managed, with 1 as the lowest and 6 as
the highest. The command defaults to tier 1 if no selection is provided.
/roll
- Roll a daily profile
Generates a brand-new character and profile once daily. Daily reset occurs at
midnight UTC. The character and profile are saved to the user profile that
initiated the command and will appear in the /listprofiles
command.
/showprofile {name} {profile_id} {rarity} {user}
- Display either a given profile or a selectable list of profiles
If profile_id
is specified, the command displays the requested profile, if
it exists. The can include profiles linked to other users if the author knows
the profile ID. Specifying profile_id
will ignore all other parameters. The
/listprofiles
command can be used to find profile IDs.
If name
is specified, the command will look for profiles with names that at
least partially match the specified name. If name
is not specified, all
profiles belonging to the determined user will be displayed.
If the user only owns one profile or if the specified name
is specific enough
the single profile will be shown. Otherwise, a dropdown list of profiles will
be displayed. Selecting a specific profile will cause it to be posted to
the channel and the dropdown re-posted.
If rarity
is specified, the command will filter the results provided by the
selected rarity.
If user
is specified, the command will only look for profiles that user owns.
If user
is not specified, the command will look for profiles that the user
that initiated the command owns.
The dropdown also has next
, back
, and cancel
options. The dropdown will
deactivate after 100 seconds of inactivity or if the cancel
option is chosen.
The next
and back
options viewing more than one page of profiles, as
Discord only allows dropdowns of 25 entries.
/showsummary {type}
- Show a summary of different user content.
Displays one of three kinds of player summaries for a given user: Characters, Economy, or Inventory. Each provides generalized information about a player's overall status and progress in the game.
The command defaults to showing the author's Inventory information if type nor user is provided.
/testget
- Test GET
Makes a basic HTTP get to the webui back-end to verify it's there and works. Also verifies the internal data path works (i.e. posting a job to the queue).
This command is limited to Guild (server) managers only.
/testpost
- Test POST
Runs a pre-defined job through the webui interface, verifying that the SD server is able to provide data to a known request. Meant for verifying the server's ability to actually supply data.
This command is limited to Guild (server) managers only.
/testroll
- Test Roll
Performs a test version of the /roll
command using known data. Useful as a
test/diagnostic tool to confirm the bot has access to all necessary resources
(such as the database and Stable Diffusion Webui).
This command is limited to Guild (server) managers only.
/testshowprofile
- Test Show Profile
This command displays a test profile in the same manner as the /showprofile
command. It is useful as a debugging/diagnostic feature to ensure that data
can be properly retrieved from the database and displayed by Discord.
This command is limited to Guild (server) managers only.
Also see the changelog and roadmap.
- No automated way to switch dataset types.
- Sharding not yet implemented.