如何使用 PyTelegrambotAPI 实现倒计时?
How to implement countdown timer with PyTelegrambotAPI?
我正在尝试在我的电报机器人中实现一些"looks like"动画倒计时:
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)
有时运行良好,但有时会出现错误:
A request to the Telegram API was unsuccessful. The server returned HTTP 400 Bad Request. Response body:error_code:400,description:"Bad Request: message is not modified
我个人不建议您在短时间内如此频繁地向电报发送请求。您可能会因请求过多而超时。
我在这里给你的两个建议:
- 跳过任何失败的更新。重试只会花费太长时间
- 使用更大的时间间隔(例如 2 秒)更新消息,让 Telegram 服务器有足够的时间意识到消息已更新。
我正在尝试在我的电报机器人中实现一些"looks like"动画倒计时:
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)
有时运行良好,但有时会出现错误:
A request to the Telegram API was unsuccessful. The server returned HTTP 400 Bad Request. Response body:error_code:400,description:"Bad Request: message is not modified
我个人不建议您在短时间内如此频繁地向电报发送请求。您可能会因请求过多而超时。 我在这里给你的两个建议:
- 跳过任何失败的更新。重试只会花费太长时间
- 使用更大的时间间隔(例如 2 秒)更新消息,让 Telegram 服务器有足够的时间意识到消息已更新。