我的电报机器人不再发送消息。我收到此错误:“RuntimeWarning:从未等待协程‘Bot.send_message’”。
from telegram import Bot
bot_token = 'xxx'
chat_id = 'xxx'
message = 'TEST'
bot = Bot(token=bot_token)
bot.send_message(chat_id=chat_id, text=message)
我假设您正在使用
python-telegram-bot
软件包?
python-telegram-bot
文档,Bot.send_message
是一个 async 函数。这意味着调用它时,需要使用 await
关键字。
尝试更改此行...
bot.send_message(chat_id=chat_id, text=message)
...对此:
await bot.send_message(chat_id=chat_id, text=message)