电报机器人不再工作了。运行时警告:从未等待过协程“Bot.send_message”

问题描述 投票:0回答:1

我的电报机器人不再发送消息。我收到此错误:“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
1个回答
0
投票

我假设您正在使用

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)
© www.soinside.com 2019 - 2024. All rights reserved.