문제 설명
Python과 함께 스레딩을 사용할 때 발생하는 코루틴 오류, RuntimeWarning: 코루틴 'time_messege'가 기다리지 않았습니다. (Coroutine error when using threading with python, RuntimeWarning: coroutine 'time_messege' was never awaited)
Python으로 스레딩을 사용할 때 이 2가지 ** 코루틴 오류를 수정하는 방법을 알고 있습니다. 이것은... :
C:\Users\PC0\Anaconda3\lib\threading.py:870: RuntimeWarning: coroutine 'time_messege' was never awaited
self._target(*self._args, **self._kwargs)
RuntimeWarning: Enable tracemalloc to get the object allocation traceback
하지만 여전히 작동하지 않습니다:
async def on_ready(self) ‑> None:
print("Logged on as {0}!".format(self.user))
x = threading.Thread(target=time_messege) #Creo un thread independiente del main_thread
x.start()
사실은 그 오류가 나타나는 이유를 더 이상 이해할 수 없다는 것입니다. 오류 2개.
참조 솔루션
방법 1:
time_message
is an async function but when you start it, you aren't awaiting it. However I do not recommend using threading in your bot. time.sleep will lead to blocking in your bot.
discord.py has its own native extension for making task loops. You should check this out, as it is made to work with an asynchronous environment.
(by Electrisik Vocal、Ay355)