Zero6992 / chatGPT-discord-bot

Integrate ChatGPT into your own discord bot
GNU General Public License v2.0
2.6k stars 699 forks source link

Multi-threading problem #375

Closed programerr01 closed 4 months ago

programerr01 commented 1 year ago
2023-04-28 18:12:54 ERROR    src.aclient -> Error while sending system prompt: 400 Bad Request (error code: 50006): Cannot send an empty message
Traceback (most recent call last):
  File "/home/ubuntu/chatGPT-discord-bot/src/aclient.py", line 166, in send_start_prompt
    await channel.send(response)
  File "/home/ubuntu/.local/lib/python3.9/site-packages/discord/abc.py", line 1561, in send
    data = await state.http.send_message(channel.id, params=params)
  File "/home/ubuntu/.local/lib/python3.9/site-packages/discord/http.py", line 744, in request
    raise HTTPException(response, data)
discord.errors.HTTPException: 400 Bad Request (error code: 50006): Cannot send an empty message
2023-04-28 18:12:55 INFO     src.bot -> ChatGPT#8329  is now running!
Task exception was never retrieved
future: <Task finished name='Task-16' coro=<aclient.process_messages() done, defined at /home/ubuntu/chatGPT-discord-bot/src/aclient.py:54> exception=RuntimeError("Task <Task pending name='Task-16' coro=<aclient.process_messages() running at /home/ubuntu/chatGPT-discord-bot/src/aclient.py:56>> got Future <Future pending> attached to a different loop")>
Traceback (most recent call last):
  File "/home/ubuntu/chatGPT-discord-bot/src/aclient.py", line 56, in process_messages
    message, user_message = await self.message_queue.get()
  File "/usr/lib/python3.9/asyncio/queues.py", line 166, in get
    await getter

No Output for /chat command

VXRKS commented 1 year ago

I'm getting this same exact problem is there a way to fix? i'm not sure I see the solution here.

python3 main.py /home/vorks/.local/lib/python3.9/site-packages/revChatGPT/__init__.py:27: UserWarning: The current Python is not a recommended version, 3.10+ is recommended __import__("warnings").warn( 2023-05-01 13:22:51 INFO discord.client logging in using static token 2023-05-01 13:22:52 INFO discord.gateway Shard ID None has connected to Gateway (Session ID: 9230bd30cde7bdd545e3ac606c973ebe). 2023-05-01 13:22:54 INFO src.aclient -> No Channel selected. Skip sending system prompt. 2023-05-01 13:22:54 INFO src.bot -> Abyss A.I ☢#9464 is now running! Task exception was never retrieved future: <Task finished name='Task-12' coro=<aclient.process_messages() done, defined at /home/vorks/Desktop/chatGPT-discord-bot-1.4.1/src/aclient.py:54> exception=TypeError("object Future can't be used in 'await' expression")> Traceback (most recent call last): File "/home/vorks/Desktop/chatGPT-discord-bot-1.4.1/src/aclient.py", line 56, in process_messages message, user_message = await asyncio.run_coroutine_threadsafe( TypeError: object Future can't be used in 'await' expression

programerr01 commented 1 year ago

@VXRKS do put discord channel link in .env file

VXRKS commented 1 year ago

I have previously it just randomly stopped working and giving out that error. That's the only reason I took it out was due to that.

Zero6992 commented 1 year ago

What is the environment you're running the code in, and python version?

VXRKS commented 1 year ago

I'm running in a vm on parrot.os/ linux and not sure on python version

programerr01 commented 1 year ago

@VXRKS it's debian with python 3.10

programerr01 commented 1 year ago

@Zero6992 message_queue.get() is not able to get latest messages due to the fact that it's not on the main loop itself . i think it's something to do with discord client thread and the main thread.

chatGPT-discord-bot/src/aclient.py", line 57, in process_messages
    message, user_message = await self.message_queue.get()
  File "/usr/lib/python3.9/asyncio/queues.py", line 166, in get
    await getter
RuntimeError: Task <Task pending name='Task-15' coro=<aclient.process_messages() running at /home/ubuntu/chatGPT-discord-bot/src/aclient.py:57>> got Future <Future pending> attached to a different loop
Zero6992 commented 1 year ago

I made some corrections in bot.py, but I'm not sure if it can fix this issue because I can't reproduce the error in my environment

programerr01 commented 1 year ago

@Zero6992 if the code is pushed to the repo, i can give it a try and let you know

Zero6992 commented 1 year ago

@Zero6992 if the code is pushed to the repo, i can give it a try and let you know

already pushed

programerr01 commented 1 year ago

ok

programerr01 commented 1 year ago

@Zero6992 still having the same error OS : Debian 5.10.162-1 python 3.9.2