파이썬 텔레그램 sendMessage 오류날 때 해결책 RuntimeWarning: coroutine 'Bot.send_message' was never awaited


import telegram

bot = telegram.Bot(TOKEN)
bot.sendMessage(chat_id=tid, text=msg)




파이썬에서 텔레그램으로 메세지를 보내려고 하는데,
아래와 같은 오류가 발생


RuntimeWarning: coroutine 'Bot.send_message' was never awaited
  bot.sendMessage(chat_id=tid, text=msg)
RuntimeWarning: Enable tracemalloc to get the object allocation traceback


과거에는 잘 되던 소스인데, 지금은 오류나는 걸 보면, 라이브러리가 업데이트가 된 것 같다.

비동기화(coroutine)에 대한 부분을 추가해줘야 한다.


import telegram
import asyncio

bot = telegram.Bot(TOKEN)
asyncio.run(bot.sendMessage(chat_id=tid, text=msg))







Written by dukgun.com

Post a Comment

다음 이전