본문 바로가기
Error

[Error] Python 텔레그램 봇 v20.0 RuntimeWarning

by dantriss 2023. 1. 15.

파이썬으로 텔레그램 봇을 만들어보고 싶어서 다른 블로그들을 따라서 해보았는데

"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="테스트 중입니다."))

 

 

해당 블로거님 덕분에 드디어 잘 수 있을것 같다

 

 

 

 

 

참고한 블로그 

https://wonderdayss.tistory.com/entry/python-telegram-bot-v200-%EC%97%90%EB%9F%AC-%EB%82%A0-%EB%95%8C-%ED%95%B4%EA%B2%B0%EB%B0%A9%EB%B2%95RuntimeWarning-coroutine-Botsendmessage-was-never-awaited

댓글