This template repository accompanies the Deploy Your Own (Not) Midjourney Bot on Fly GPUs blog post. This README will guide you through setting up the bot and server on Fly.io.
Deploy the Fooocus API Server App
To deploy the Fooocus API server, follow these steps:
-
Create a new app:
fly apps create [YOUR APP]
-
Clone the repo. You'll need clone the submodules too:
git clone --recurse-submodules git@github.com:fly-apps/not-midjourney-bot.git
then:
cd not-midjourney-bot/server
-
From the base directory, use the Fly CLI to deploy the server:
fly deploy --no-public-ips
Optionally use the pre-built image to speed things up:
fly deploy -i ghcr.io/fly-apps/not-midjourney-bot:server --no-public-ips
-
Now, let's allocate a private IPv6 so we can access the API via Flycast private load-balancing:
fly ips allocate-v6 --private
To invite your bot to your server and grant it the necessary permissions, you'll need to generate an OAuth2 URL using the Discord Developer Portal.
Follow these steps to create the URL and define the bot's capabilities:
-
In the Discord Developer Portal, select your application if you have one, or create one if you don't.
-
Create a new "bot user".
-
Under "Privileged Gateway Intents", be sure to toggle "MESSAGE CONTENT INTENT" on.
-
Navigate to the "OAuth2" page in the sidebar.
-
Under the "OAuth2 URL Generator" section, you'll find the scopes and permissions settings.
-
In the "SCOPES" section, select the checkboxes for:
bot
– This allows your application to use bot-related features.applications.commands
– This permits your bot to create and handle application commands (slash commands).
-
Once you've selected the scopes, the "BOT PERMISSIONS" section will become active.
-
In the "BOT PERMISSIONS" section, you'll need to specify what actions your bot can perform on the server. Under "TEXT PERMISSIONS", select the following permissions:
Send Messages
– Allows your bot to send messages in the chat.Create Public Threads
– Enables your bot to create new public threads.Send Messages in Threads
– Permits your bot to send messages in threads that it has access to.Attach Files
– Your bot can attach files to the messages it sends.Add Reactions
– Allows your bot to add reactions to messages.Use Slash Commands
– Enables your bot to interact with users through slash commands.
Your permissions should now look like this in the Developer Portal:
- After selecting the permissions, the page will automatically generate an OAuth2 URL at the bottom of the section.
- Copy this URL, and use it to invite your bot to your server. Simply paste the URL into your web browser, choose a server to invite your bot to, and confirm the permissions.
It's important to only grant the permissions that your bot needs to function as intended. Excessive permissions can pose a security risk.
By following these steps, your bot will be set up with the appropriate permissions to interact with users on your server.
Note
The Discord bot app will be deployed on non-GPU hardware.
To deploy your Discord bot, you'll need to perform the following steps:
-
Set the
DISCORD_TOKEN
secret using the Fly CLI:fly secrets set DISCORD_TOKEN=your_discord_bot_token --stage
Replace
your_discord_bot_token
with the actual token of your Discord bot. -
Set the
FOOOCUS_API_URL
secret. This will be the URL where your bot can communicate with the deployed Fooocus API server:fly secrets set FOOOCUS_API_URL="http://$(fly config show -c ./server/fly.toml | jq -r '.app').flycast:80" -c ./bot/fly.toml --stage
-
Deploy your bot to Fly.io using the Fly CLI:
fly deploy -c ./bot/fly.toml --no-public-ips
Optionally use the pre-built image to speed things up:
fly deploy -i ghcr.io/fly-apps/not-midjourney-bot:bot -c ./bot/fly.toml --no-public-ips
Retrieve a Fly.io authentication token using the command fly auth token
and include it in your GitHub Actions repository secrets as FLY_API_TOKEN
. Additionally, set your DISCORD_TOKEN
. After completing these steps, navigate to Actions > Fly Deploy, and initiate the deployment workflow by clicking "Run Workflow." Choose all
to deploy both the bot and server to Fly.io.
The bot exposes an /imagine
slash command in your Discord server.
Note
The /imagine
command is asynchronous, so it may take some time for the bot to generate and send the image.
To use it:
- Open Discord and navigate to the server where your bot is invited.
- Type
/imagine
in the chat input box to trigger the slash command. - Write your text-to-image prompt for the image you want to generate. The more creative you are the better results you will get!
- Optionally, you can specify the styles to use in the image generation. You can provide up to three styles by using the style1, style2, and style3 options.
- You can also choose to run the image generation at quality instead of speed by setting the quality option to
True
. - If you want to specify the aspect ratio for the image, you can use the ar option. The default is 1152×896px.
- If you want to provide a negative prompt for the image, you can use the negative option.
- Once you have provided all the necessary options, press Enter to execute the command.
- The bot will generate the image based on the provided prompt and options. The generated image will be sent as an image response in the chat.
Create an issue or ask a question here: https://community.fly.io/