파이썬으로 텔레그램 봇을 만들어보고 싶어서 다른 블로그들을 따라서 해보았는데
"RuntimeWarning: coroutine 'Bot.send_message' was never awaited bot.send_message " 라며 작동이 되지 않았다.
import warnings 를 사용해서 ignore도 해보았지만 역시나 전혀 소용 없었다.
그렇게 이것저것 검색하면서 떠돌아 다니던 도중 한 블로그를 발견해서 바로 해결 했다.
바로 asyncio을 이용해서 다음과 같이 실행 시키는 것이다
import telegram
import asyncio
token = "토큰 값"
id = "id 값"
bot = telegram.Bot (token)
asyncio.run(bot.send_message(chat_id=id, text="테스트 중입니다."))
해당 블로거님 덕분에 드디어 잘 수 있을것 같다
참고한 블로그
댓글