Midjourney / Discord to Lightroom automation – step by step – for 2024

Midjourney is fun, but the Discord-based interface is somewhat annoying if you want to make a lot of images. To get all the images you generate, you have to upscale all 2×2 previews and save them manually. It can get pretty tiring, so instead of making better images, I spent a bit of time automating the download and import process. With this code, a Discord bot will monitor your server, watch for Midjourney messages, process all images, and upload them to your Lightroom CC cloud account. Run the script anywhere, a Raspberry Pi or a cheap cloud server, and keep making images.

If you want to get started right away, the code is github.com/softplus/midjourney_lightroom

This looks like a long post – it’s just a collection of many small steps. If you’ve run something from GitHub before, you can do it. All of this works under Ubuntu, I’m not bored enough to try it out in other operating systems. YMMV.

Inspired by Michael King’s guide to automatically download Midjourney images.


You will need the following:

  • Somewhere to run the code. I use a computer with Ubuntu.
  • A private Discord server. Make a new one if you want, they’re “free”.
  • A Discord bot key (we’ll make that below)
  • An Adobe Lightroom CC API key (we’ll make that below)
  • A Midjourney account (#obviously)

It will do the following:

  • The bot joins your private server & channel.
  • You’ve invited Midjourney there too.
  • When you get a result from Midjourney, it will download the image, and upload them to Lightroom.
  • Once a day you’ll need to authenticate for Lightroom.

Clone & set up the project

This is for Ubuntu. Adjust as needed. We’re cloning the project, setting up a virtual environment, installing the pre-requisites, and making a default setting (.env) file. In a command window, enter the following:

git clone https://github.com/softplus/midjourney_lightroom # get the repo
cd midjourney_lightroom         # enter the folder
virtualenv .venv && source .venv/bin/activate # set up a virtual environment
pip install -r requirements.txt # install requirements
cp sample.env .env              # copy the settings file

Lightroom CC API key

We’re creating a new project, selecting the Lightroom API, and getting the OAuth2 keys.

  1. Go to https://developer.adobe.com/console/home
  2. Create a new project
  3. Click ‘Add API’
  4. Find ‘Lightroom Services (requires review)’ in the list, click ’next’
Adobe API dashboard: picking services screenshot
  1. For Oauth 2.0 authentication, select ‘Web App’
  2. Enter ‘https://lowly-occipital-croissant.glitch.me/’ as redirect URI and ‘https://lowly-occipital-croissant\.glitch\.me/’ as Redirect URI pattern (with the extra \’s):
See also  Getting Started with Midjourney Prompts for Realistic Photo Images
Adobe API dashboard: setting up Oauth2
  1. Copy the ‘Client ID’ into your .env file.
  2. Click ‘Retrieve client secret’, and copy the client secret into your .env file.
  3. Done! (for this)

Discord server

This (probably) works best with a separate Discord server, so let’s set that up. Here’s the official guide.

  1. In Discord, click on the “+” to add a new server
Where the ‘add server’ button is in Discord
  1. Select ‘Create My Own’
  2. Select ‘For me and my friends’
  3. Enter a server name. Anything. Your favorite cheese.

Now it’s time to add the Midjourney bot.

  1. Go to your direct messages
  2. Select the Midjourney bot
  3. Click on the name of the bot on top:
Screenshot of adding a bot to a server in Discord
  1. Click ‘Add to server’
  2. Select your server, click ‘Continue’
  3. Leave settings default, click ‘Authorize’ (and do captcha)

Now go to your server into one of the channels, you should see a confirmation that the bot was added. Try to make an image, it should work normally.

Create a Discord bot

  1. Go to https://discord.com/developers/applications
  2. Click ‘New Application’
  3. Pick an application name (anything) and confirm that you’re not a jerk.
  4. Click ‘Create’. You now have a bot!
  5. Select ‘Bot’ in the sidebar.
  6. In ‘Build-A-Bot’, click ‘Reset Token’. This shows a long token.
  7. Click ‘Copy token’ and save it in your .env file as DISCORD_TOKEN.
  8. Still in ‘Bot’, scroll down and enable the intents: ‘Presence intent’, ‘Server members intent’ and ‘Message content intent’
Selecting Discord bot permissions
  1. Select ‘OAuth2’ in the sidebar, and go to ‘URL generator’
  2. In ‘Scopes’, select ‘Bot’ – this adds the bot permissions on the bottom.
Getting the Discord bot’s authentication URL
  1. Scroll down, and under ‘Bot permissions’ select ‘Read messages / View channels’
  2. Go to the bottom, copy the Generated URL, and open it in a separate browser tab.
  3. This starts with adding the bot to your server. Select your server and continue.
Adding the Discord bot to your server
  1. Confirm the ‘Read messages’ permission. Click ‘Authorize’. Do Captcha.
  2. Your bot is now in the Discord! You should see a confirmation in the channel.

Now you have Lightroom, Discord, and the permissions set up. Your .env file should minimally contain settings for DISCORD_TOKEN, LR_CLIENT_ID, and LR_CLIENT_SECRET.

Run the bot

In the command window where you installed the code, you should be able to run it now:

python3 main_script.py
# stuff happens now

It should log in to Discord, and wait for more:

Creating new salt for random file names.
Lightroom authentication code invalid, starting fresh.
401 Client Error: Unauthorized for url: https://lr.adobe.io/v2/catalog
2023-05-01 09:07:24 INFO     discord.client logging in using static token
2023-05-01 09:07:25 INFO     discord.gateway Shard ID None has connected
to Gateway (Session ID: 1234567890abcdef1234567890abcdef). 
Logged in as chessetesters#2484 (ID: 1234567890123456789)
Bot connected, enter 'hi!' to confirm

The Adobe error is because you haven’t logged in to your Lightroom account yet – we’ll do that next. You won’t see anything in Discord just yet, since it doesn’t know which channel to post to.

See also  How To Generate Prompts For Midjourney Using ChatGPT

In Discord, enter ‘hi!’ into the chat. This will trigger the bot, who will give you the URL to authenticate for Lightroom. The URL is specific to this bot.

Screenshot of bot asking for Lightroom authentication

Click the link, and (potentially) sign in to your Adobe account (if not signed in already). It will redirect you to a page with the auth-code. The auth-code is specific to the bot and your account.

Lightroom authentication code screen

Click on the auth code, this will select it and copy it into your clipboard. Paste the auth code into Discord (including the ‘auth!’ part in the beginning). The bot will respond with ‘Lightroom authentication ok’ if it’s good. The authentication expires after 24 hours, so this will trigger for you once a day. You’re all set now!

Try an /imagine command. Midjourney should generate the image. Your script should pick it up. Lightroom should show the 4 generated images. You don’t need to use ‘Upscale’.

Here’s what you might see in the script output:

Message: Please authenticate here and paste the results here:
Message: https://ims(...)e%2F
Message: auth! ey(...)g
Message: Lightroom authentication is ok.
Message: **cheese is holey --v 5** - <@1234567890123456789> (Waiting to start)
Message: **cheese is holey --v 5** - <@1234567890123456789> (fast)
  Image downloaded: johnmu_cheese_is_holey_01234567-89ab-cdef-0123-456789abcdef.png
  Stored: -cABCDEFGabcdefg012345.png
  Stored: VnABCDEFGabcdefg012345.png
  Stored: u1ABCDEFGabcdefg012345.png
  Stored: zLABCDEFGabcdefg012345.png

The images are stored in a folder called ‘out’ locally, and uploaded to Lightroom CC. You’re essentially done now, this will work. Adding the spreadsheet below makes it easier to track back prompts for images you created, but it’s optional.

Setting up a Google Spreadsheet for image details

The images are renamed into “random” names (MD5 of original URL + salt from your settings). This prevents accidentally leaking the prompt or the Midjourney GUID (which lets people look up the details and your other images). It also makes for shorter filenames.

See also  Guide to Prompts for Midjourney V5 with ChatGPT-4

A local file out/_log.csv tracks the original file names, links to the Discord message, and the Midjourney GUID. It’s also added into a Google Sheet with help of a Google Forms hack. Here’s how to set it up.

  1. Go to https://forms.new/ – this creates a new Google Form
  2. Name it reasonably.
  3. Add 8 ‘short answer’ text fields. They don’t need to be named, but the field names I use are: New UUID, Old UUID, Prompt, Seed, URL, Filename, Job URL, Image URL. (The seed is future-looking, it can’t be picked up currently.)
Screenshot of a part of a Google Form setup
  1. Click on the ‘Responses’ tab, and select ‘Link to Sheets’. Select ‘Create a new Spreadsheet’.
  2. Go back to the form, click the preview link (the funky weird eye-icon on top).
  3. Copy the URL and add it to your .env file as FORM_URL.
  4. Restart your script, if it’s running.

Try making an image. It should now upload to Lightroom, and get logged in the spreadsheet.

This is it. Create away.

Final thoughts

Random notes

  • This all depends a bit on Midjourney’s current setup (filenames, Discord message formatting, file formats, previews containing the full image, etc). If any of this changes, this script might not work anymore.
  • Recently, Midjourney moved to .webp for preview images, which had to be adjusted here.
  • It’s possible that Midjourney doesn’t like this, though since it’s not automatically pushing requests to Midjourney, maybe it’s fine?
  • I can’t promise to keep up with Midjourney changes.
  • The Adobe Lightroom API has a weird bug that doesn’t accept a date stamp for images uploaded. No idea how to report that.
  • This only downloads new images, it doesn’t go through your channel history.

Possible future updates

  • Document how to run this on a free instance in Google Cloud
  • Document how to run this on a Raspberry Pi (should be trivial).
  • Auto-delete images by responding with “X” after some time after importing. Keep your Midjourney profile & Discord clean.
  • Add a command to select an album to add images to.
  • Auto-pick album name based on prompt.
  • Run Open-AI’s API over the prompt to generate hashtags for auto-classification.
  • Process part of chat history.

Mohamed SAKHRI
Mohamed SAKHRI

I'm the creator and editor-in-chief of Tech To Geek. Through this little blog, I share with you my passion for technology. I specialize in various operating systems such as Windows, Linux, macOS, and Android, focusing on providing practical and valuable guides.

Articles: 1273

Newsletter Updates

Enter your email address below and subscribe to our newsletter

Leave a Reply

Your email address will not be published. Required fields are marked *