#Dalle-2 in Discord Bot w/Python - Help!

3 messages · Page 1 of 1 (latest)

fringe lagoon
#

Hi there - Here is the relevant bit of my code

@bot.command()
async def generate(ctx, *, prompt: str):
    if ctx.author == bot.user:
        return
    response = openai.Image.create(
        n=1,
        size="1024x1024"
    )
    image_url = response['data'][0]['url']
    await ctx.channel.send(response.choices[0].message.content)
    print(f'Command {ctx.command} invoked by {ctx.author}')
#

And here's my error:

Traceback (most recent call last):
  File "/home/admin/.local/lib/python3.9/site-packages/discord/ext/commands/core.py", line 229, in wrapped
    ret = await coro(*args, **kwargs)
  File "/home/admin/scripts/starshireGPT/starshirebot.py", line 88, in generate
    response = openai.Image.create(
  File "/home/admin/.local/lib/python3.9/site-packages/openai/api_resources/image.py", line 36, in create
    response, _, api_key = requestor.request(
  File "/home/admin/.local/lib/python3.9/site-packages/openai/api_requestor.py", line 226, in request
    resp, got_stream = self._interpret_response(result, stream)
  File "/home/admin/.local/lib/python3.9/site-packages/openai/api_requestor.py", line 619, in _interpret_response
    self._interpret_response_line(
  File "/home/admin/.local/lib/python3.9/site-packages/openai/api_requestor.py", line 682, in _interpret_response_line
    raise self.handle_error_response(
openai.error.InvalidRequestError: 'prompt' is a required property

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/home/admin/.local/lib/python3.9/site-packages/discord/ext/commands/bot.py", line 1350, in invoke
    await ctx.command.invoke(ctx)
  File "/home/admin/.local/lib/python3.9/site-packages/discord/ext/commands/core.py", line 1023, in invoke
    await injected(*ctx.args, **ctx.kwargs)  # type: ignore
  File "/home/admin/.local/lib/python3.9/site-packages/discord/ext/commands/core.py", line 238, in wrapped
    raise CommandInvokeError(exc) from exc
discord.ext.commands.errors.CommandInvokeError: Command raised an exception: InvalidRequestError: 'prompt' is a required property

#

Any insight would be appreicated!