设置为True时,CallbackQueryHandler不返回user_data

时间:2019-01-04 10:36:41

标签: python-3.x python-telegram-bot

我试图在我的Telegram机器人上使用按钮,以获取用户输入。我需要传递的一件事是电报用户ID,但是当使用CallbackQueryHandler且pass_user_data设置为Ture时,我只会得到一个空字典吗?

尝试运行调试器,但仍然看不到我要去哪里。我使用的是Python 3.7。

在main()中:

dp = updater.dispatcher
dp.add_handler(CallbackQueryHandler(listbots, pattern='viewbots', pass_user_data=True))

def listbots(bot, update, user_data):
    logging.debug('User_Data:')
    logging.debug(user_data)
    logging.debug('Update:')
    logging.debug(update.message.from_user.id)

我希望看到单击按钮的用户数据,但我什么也没得到:

2019-01-04 20:31:46,474 - root - DEBUG - User_Data:
2019-01-04 20:31:46,474 - root - DEBUG - {}
2019-01-04 20:31:46,474 - root - DEBUG - Update:
2019-01-04 20:31:46,474 - telegram.ext.dispatcher - ERROR - An uncaught error was raised while processing the update
Traceback (most recent call last):
File "/Users/yogi/PycharmProjects/bottest/venv/lib/python3.7/site-packages/telegram/ext/dispatcher.py", line 279, in process_update
handler.handle_update(update, self)
File "/Users/yogi/PycharmProjects/bottest/venv/lib/python3.7/site-packages/telegram/ext/callbackqueryhandler.py", line 143, in handle_update
return self.callback(dispatcher.bot, update, **optional_args)
File "/Users/yogi/PycharmProjects/bottest/pb-userbot.py", line 179, in listbots
logging.debug(update.message.from_user.id) 
AttributeError: 'NoneType' object has no attribute 'from_user'

0 个答案:

没有答案