How to make a Discord bot handle 'requests.post' as a command instead of plain text in Discord

368 views Asked by At

In my python code, im generating prompts using ChatGPT and sending them automatically to the discord bot Midjourney. With the /imagine part that already comes with the generated prompts, it usually commands the bot to create the images thats it's prompted with (when you copy and paste it with the website), but when sending those prompts per

# Open The File Containing The Prompts
time.sleep(0.25)
print("Copying Prompts...")
file_path = "...\Output.txt"
with open(file_path, 'r') as file:
    prompts = [line.strip() for line in file if line.strip()]

# Sending Prompts To Discord
time.sleep(0.25)
print("Sending Prompts...")
for prompt in prompts:
    payload = {
        'content': prompt
    }

    r = requests.post("discord channel id", json=payload, headers=header)
    time.sleep(1.5)

print("Prompts Sent")

the midjourney discord bot doesnt recognize it as a command but rather as plain text. What can i do?

I tried sending the prompts using json=payload instead of data=payload but that didn't work either.

2

There are 2 answers

2
Ivan On

This article describes how to construct this. Basically you have to instantiate a new object and list the options (parameters) for the command also, though I'm not sure how you tried to achieve this as you didn't show any code.

How to invoke a discord bot command via rest api?

0
Nikoole On

You need to use API layer to Midjourney like userapi.ai