pyTelegramBotAPI get_updates() 函数

问题描述

我使用 get_updates() 函数的目的是在我从崩溃或临时关闭的机器人重新启动我的机器人时处理来自用户的待处理请求。

恢复我的机器人时,我想确保在停机期间没有用户重复请求尝试,我需要处理这些请求以避免重复输入。

我可以使用 get_updates() 函数检索待处理的请求。

pending_updates = bot.get_updates()

for pending_request in pending_updates:
    print('Pending Request',pending_request)

返回值如下

待处理请求 {'update_id': 268581735,'message': {'content_type': 'text','id': 492,'message_id': 492,'from_user': ,'date': 1625846407,'chat': ,'forward_from': None,'forward_from_chat': None,'forward_from_message_id': None,'None,'forward_nameforward' :无,'forward_date':无,'reply_to_message':无,'via_bot':无,'edit_date':无,'media_group_id':无,'author_signature':无,'text':'20','entities' :无,'caption_entities':无,'audio':无,'document':无,'photo':无,'sticker':无,'video':无,'video_note':无,'voice':无,'标题':无,'联系':无,'位置':无,'场地':无,'动画':无,'骰子':无,'new_chat_member':无,'new_chat_members':无,' left_chat_member':无,'new_chat_title':无,'new_chat_photo':无,'delete_chat_photo':无,'group_chat_created':无,'supergroup_chat_creat ed':无,'channel_chat_created':无,'migrate_to_chat_id':无,'migrate_from_chat_id':无,'pinned_message':无,'invoice':无,'successful_payment':无,'connected_website':无,'reply_markup' : 无,'json': {'message_id': 492,'from': {'id': 1569061133,'is_bot': False,'first_name': '简明','last_name': 'Shen','language_code ': 'en'},'chat': {'id': 1569061133,'type': 'private'},'text':'20'}},'edited_message':无,'channel_post':无,'edited_channel_post':无,'inline_query':无,'chosen_inline_result':无,'callback_query':无,'shipping_query':无,'pre_checkout_query':无,'poll':无,'poll_answer':无,'my_chat_member':无,'chat_member':无}

我尝试使用 dict() get() 方法访问数据,但显示错误

print('Pending Request',pending_request.get('update_id')) AttributeError: 'Update' 对象没有属性 'get'

我不明白我得到的数据是不是字典?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)