How to Make a Midjourney Discord Bot to Automatically Download AI-Generated Images: A Python Step-by-Step Guide

How to Make a Midjourney Discord Bot to Automatically Download AI-Generated Images: A Python Step-by-Step Guide


Are you tired of using boring communication platforms? Discord has become increasingly popular in recent years, offering a wide range of functionalities to enhance the user experience on the platform. One fascinating application of Discord bots is the ability to automatically download AI-generated images. In this blog post, we will provide a comprehensive step-by-step guide on creating a Midjourney Discord bot that can seamlessly generate and download AI-generated images using Python.

A Midjourney bot Discord is a bot that works within the Discord platform to execute certain activities, like generating and downloading AI-generated graphics. The word “midjourney” refers to the bot’s capacity to generate visuals during a conversation or interaction, adding a dynamic and interactive element to the Discord experience.

To build Midjourney Discord bot, we will use Python and modules such as for Discord API integration. Furthermore, we will investigate the potential of AI picture-generating models such as DALL-E to generate unique and creative images on the fly.

Also read: Exploring the Power of ChatGPT: Use Cases, Applications, Principles, ChatGPT API, Pros & Cons

Auto AI tool Chatgpt


Before we begin the bot-building process, let’s double-check that you have everything you need:

  1. Discord Account: If you don’t already have one, create one at
  1. Python Installed: Check that Python is installed on your PC. The most recent version is available at
  1. Library: To connect with the Discord API, we will use the library. Use pip to install it:
pip install

Midjourney API Key: An API key is required to access Midjourney’s picture store. You can get one by registering at

Making Your Own Discord Server

Are you ready to launch your own Discord server? It’s a wise choice, especially if you want to manage who has access to your server. To get you started, here’s a quick-start instruction.

1. First, create an account or log in to Discord. Sign in if you already have an account

2. Look for the ‘+’ button on the left side of your screen once you’ve checked in.

Midjourney Discord Bot -

4. Click it to start a new server.

Midjourney Discord Bot -

3. Name your server and choose the region that is nearest to you. Keep in mind that the server name should be distinctive and descriptive.

Midjourney Bot Discord -

Midjourney Bot Discord -

5. The exciting part now begins: customising your server settings. You can organise and safeguard your server by adding channels, roles, and permissions.

Midjourney Bot Discord -

That’s all! You have successfully established your own Discord server.Continue reading to find out how to integrate AI bots into your private Discord server and take it to the next level.

Setting Up the MidJourney Bot Account

In order to add AI bots to your private Discord server, you must first create a MidJourney bot account. Here’s how to go about it:

Step 1: Go to the MidJourney website and sign up, which is a simple and short process.

Midjourney Bot Discord -

Step 2: Create an AI bot account, where you will enter the bot’s name, profile image, and other pertinent information.

Midjourney Bot Discord -

Step 3: Customise bot settings by selecting the appropriate features and characteristics for the bot. You may train the bot to recognise certain keywords and take actions in response to them.

Auto AI tools

Midjourney Bot Discord -

Step 4: Obtain bot credentials, which are the keys that enable your bot to communicate with the Discord server. You must create a Bot Token and keep it safe and secure.

Auto AI tools

Auto AI tools

It is critical to carefully design the bot while keeping in mind the goal for which you intend to employ it. You might use it to automate certain activities or to make your Discord community more interesting. Make sure to customise the bot’s name, image, and other variables to match the culture of your server. The goal is to build a bot that feels like a genuine member of your server, giving value and fun to the community.

AI Bots on the Private Discord Server

Adding AI Bots to your Private Discord Server can transform your community. Here are the measures to take: Log in to the Discord Developer site at and build an application.

Step 1: Navigate to the Discord Developer Portal. You may create, manage, and configure your Discord bots here.

Step 2: Make a new app and enable the bot option. Discord will generate a unique Client ID and Client Secret after you create an application, which you will need later.

Step 3: Obtain an authentication token for the bot. You can produce an authentication token for your bot using the Client ID and Client Secret. Copy this token because you’ll need it in step 4.

Step 4: Install the bot on your private server. To get your bot on the server, go to the Bot tab, select “Add Bot,” and paste the authentication token.

Remember that after your AI bot is added, you may customise and control it with various instructions. The options are limitless! So, let’s get started on adding some AI magic to your server!

AI Bot Customization and Control

It is critical to customise and control AI bots after adding them to your private Discord server. You can configure the bot’s settings and preferences by accessing its dashboard. After you’ve customised the bot, you may use bot commands to efficiently control it. Remember, the bot exists to make your life easier, so take advantage of it. Don’t be hesitant to try alternative settings and commands. With the proper configuration, your AI bot can become a very useful tool on your private Discord server.

Here’s a more in-depth description of what the script does:

  1. Uses your bot token to connect to the Discord API and listens for messages from the server you specify.
  2. When a message is received, the script checks to see if it contains an image. If this is the case, the script recognises it as a mid-trip preview grid image.
  3. If the image is a preview grid image, the script divides it into four independent images using Python’s Image Library (PIL).
  4. The script then stores all of the generated images in your output folder.

Let’s get started right away and create your Discord Python bot!

Creating the Python Script


Before we begin, please make sure you have the following items:

  • Python 3 is installed on your computer.
  • The and requests libraries are installed (pip install requests).

Step 1: Configure the Python script.

Now that we’ve set up our Discord bot, we can begin developing our Python script. Let’s begin by importing the necessary libraries:

import discord

from discord.ext import commands

import requests

Next, let’s set up our bot using the commands. Bot class from the discord.ext.commands module:

bot = commands.Bot(command_prefix='!')


async def on_ready():

print(f'Logged in as {}')

In this code, we construct a command instance. Bot with the command prefix! This indicates that our bot will respond to commands beginning with! We also define an event handler for the on_ready event, which is triggered when the bot is prepared to begin receiving events.

Step 2: Connect to the Mid journey API.

We can now integrate our bot with the Midjourney API to obtain AI-generated photos. To accomplish this, we will send HTTP queries to the Midjourney API using the requests library.

First, let’s write a function that accepts a prompt as input and returns an image generated by Midjourney’s AI:

def get_midjourney_image(prompt):

url = ''

headers = {'Authorization': 'Bearer YOUR_API_KEY'}

data = {'model': 'image-alpha-001', 'prompt': prompt}

response =, headers=headers, json=data)

response_json = response.json()

image_url = response_json ['data'] [0] ['url']

    return image_url

In this code, we define the function get_midjourney_image, which accepts a prompt as input. The function makes an HTTP POST request to the Midjourney API, specifying the prompt and model in the request body. The API responds with a JSON response that includes the URL of the created image.

Make sure YOUR_API_KEY is replaced with your personal Midjourney API key.

Step 3: Include a Command for Image downloading.

Now that we have our Midjourney picture download capability, we can add a command to our bot that allows people to download images by sending a message in Discord.

Let’s add a command called midjourney that takes a prompt and responds with an AI-generated image from Midjourney:


async def midjourney(ctx, *, prompt):

image_url = get_midjourney_image(prompt)

    await ctx.send(image_url)

Using the @bot.command decorator, we define a command called !midjourney in this code. As input, the command accepts a context object (ctx) and a prompt. To obtain an AI-generated image from Midjourney, the prompt is supplied to our get_midjourney_image method. ctx.send is then used to transmit the picture URL back to Discord.

Step 4: Start the Bot

Now that our bot is finished, we can test it using the commands listed below.'YOUR_BOT_TOKEN')

Make sure YOUR_BOT_TOKEN is replaced with the bot token you copied before.

When you run the script, your bot should be logged in to Discord and ready to take commands. Send a message on Discord with the mid journey command followed by a prompt to try it. The bot should answer with an AI-generated Midjourney picture.

Congratulations! You’ve successfully built a Discord bot that can download Midjourney photos automatically. Your server members will now experience magnificent pictures that have been retrieved directly from Midjourney with no manual work. Your Discord server’s engagement and attractiveness will rise as you continue to refine and customise your bot. Continue to investigate new possibilities and improve your bot’s functionality for an excellent Discord experience!


In this article, we learned how to use Python to develop a Midjourney ai Discord that can automatically download AI-generated photos. We went over how to set up a Discord bot, integrate it with the Midjourney API, and add a command to download photos. With this knowledge, you can build your own Mid journey Discord bot and learn more about this amazing AI tool.


Q1: What is the Midjourney Discord bot?

A1: The Midjourney AI Discord bot is a versatile and user-friendly bot that enhances your Discord server by fetching and presenting attractive images from Midjourney’s image collection. You can get a large choice of visually appealing photos relevant to your server’s topics and themes with a single command.

Q2: how to add midjourney bot to your discord server?

A2: It’s simple to invite the Midjourney bot to your server. To invite the bot, use the OAuth2 URL generated during the bot setup process. Ascertain that the bot is online and has the required permissions to read and write messages in the channels where it will function.

Q3: What commands does the Midjourney bot support?

A3: At the moment, the Midjourney bot only supports one primary command: download. Simply type download followed by your preferred keyword (e.g.,!download landscape) to retrieve an image from Midjourney. The bot will look for images that are related to the specified keyword and return the most relevant one to the Discord channel.

Q4: Is there a limit to how many images I can fetch using the Midjourney bot?

A4: Midjourney’s API may have rate limits in place to prevent misuse; however, as a regular user, you should be able to retrieve photographs without exceeding any restrictions. If you have any problems, please be patient and try again later.

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.