如何使用PyTelegrambotAPI实现倒数计时器?

时间:2017-04-19 18:38:24

标签: python telegram telegram-bot

我正试图在我的电报机器人中实现一些“看起来像”动画倒计时:

sent=bot.send_message(message.chat.id,'5')
time.sleep(1)
bot.edit_message_text('4',message.chat.id,sent.message_id)
time.sleep(1)
bot.edit_message_text('3',message.chat.id,sent.message_id)
time.sleep(1)
bot.edit_message_text('2',message.chat.id,sent.message_id)
time.sleep(1)
bot.edit_message_text('1',message.chat.id,sent.message_id)
time.sleep(1)
bot.edit_message_text('0',message.chat.id,sent.message_id)

有时效果很好,但有时我会收到错误:

  

对Telegram API的请求未成功。服务器返回HTTP 400 Bad Request。响应正文:error_code:400,描述:“错误请求:消息未被修改

1 个答案:

答案 0 :(得分:0)

我个人不建议您经常在很短的时间内向电报发送请求。您可能会因为太多请求而超时。 我在这里给你两个建议:

  1. 只需跳过任何失败的更新。重试只需要太长时间
  2. 使用更大的间隔(例如2秒)更新消息,以便让电报服务器有足够的时间来认识消息已更新。
相关问题