so basically i dont like bots from others and i like to do things on my own (probably a bad idea ngl), anyways im trying to build a bot that would use openai api as a response to messages. i tried consulting with the openai itself (chatgpt) but it started looping and i keep running into the same errors. (code is in python)
import discord
openai.api_key = "myapi"
def generate_response(prompt):
response = openai.Completion.create(engine="text-davinci-002", prompt=prompt, max_tokens=1024)
return response.text
intents = discord.Intents().all()
client = discord.Client(intents=intents)
@client.event
async def on_message(message):
if message.author == client.user:
return
prompt = message.content
response_text = generate_response(prompt)
await message.channel.send(response_text)
client.run("mycode")```
so that's the code and the newest error is:
```[2022-12-31 02:53:39] [ERROR ] discord.client: Ignoring exception in on_message
Traceback (most recent call last):
File "C:\Users\piotr\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\openai\openai_object.py", line 59, in __getattr__
return self[k]
KeyError: 'text'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\xxx\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\discord\client.py", line 409, in _run_event
await coro(*args, **kwargs)
File "C:\Users\xxx\source\repos\PythonApplication1\PythonApplication1.py", line 19, in on_message
response_text = generate_response(prompt)
File "C:\Users\xxx\source\repos\PythonApplication1\PythonApplication1.py", line 8, in generate_response
return response.text
File "C:\Users\xxx\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\openai\openai_object.py", line 61, in __getattr__
raise AttributeError(*err.args)
AttributeError: text
also im using the openai library version 0.25.0 cause i can't seem to find the newer ones. any help would be appreciated. also if it would be better then you can rewrite the code to a newer library or smth. ps: yes i do have the api and discord token replaced, i just deleted it for privacy reasons