python - 注册下一步电报 api
问题描述
我正在研究 bot,它正在使用它自己的用户系统。我想设置一种登录和注册功能。在启动机器人时,它建议使用内联键盘选择其中一个功能,我希望我的机器人从回调处理程序开始登录或注册序列。它必须获取用户的位置、登录名和密码,但是当我开始制作登录功能时,我意识到我无法调用 register_next_step_handler 函数。有什么方法可以像我计划的那样使用它,或者任何其他方式?
代码:
@bot.message_handler(commands=['start'])
def send_welcome(message):
markup = types.InlineKeyboardMarkup()
buttonA = types.InlineKeyboardButton('LOG IN', callback_data='log_in')
buttonB = types.InlineKeyboardButton('SIGN UP', callback_data='sign_up')
markup.row(buttonA)
markup.row(buttonB)
bot.send_message(message.from_user.id, "Please, choose the option below", reply_markup=markup)
@bot.callback_query_handler(func=lambda call: True)
def handle(call):
if str(call.data) == "log_in":
bot.send_message(call.message.chat.id, "LOG IN SEQUENCE")
bot.send_message(call.message.chat.id, "What is your position?")
bot.register_next_step_handler(call.message.chat, get_pos)
elif str(call.data) == "sign_up":
bot.send_message(call.message.chat.id, "SIGN UP SEQUENCE")
bot.answer_callback_query(call.id)
def get_pos(call):
global pos
pos = call.data
bot.send_message(call.message.chat.id, "Your position: " + pos)
错误:
Traceback (most recent call last):
File "/home/firephoenix/PycharmProjects/pythonProject/main.py", line 35, in <module>
bot.polling(none_stop=True, interval=0)
File "/home/firephoenix/.local/lib/python3.8/site-packages/telebot/__init__.py", line 619, in polling
self.__threaded_polling(none_stop, interval, timeout, long_polling_timeout, allowed_updates)
File "/home/firephoenix/.local/lib/python3.8/site-packages/telebot/__init__.py", line 678, in __threaded_polling
raise e
File "/home/firephoenix/.local/lib/python3.8/site-packages/telebot/__init__.py", line 641, in __threaded_polling
self.worker_pool.raise_exceptions()
File "/home/firephoenix/.local/lib/python3.8/site-packages/telebot/util.py", line 130, in raise_exceptions
raise self.exception_info
File "/home/firephoenix/.local/lib/python3.8/site-packages/telebot/util.py", line 82, in run
task(*args, **kwargs)
File "/home/firephoenix/PycharmProjects/pythonProject/main.py", line 21, in handle
bot.register_next_step_handler(call.message.chat, get_pos)
File "/home/firephoenix/.local/lib/python3.8/site-packages/telebot/__init__.py", line 2322, in register_next_step_handler
chat_id = message.chat.id
AttributeError: 'Chat' object has no attribute 'chat'
解决方案
推荐阅读
- react-native - 同一个屏幕在 react-navigation 的 stacknavigation 中渲染两次或三次
- kubernetes - Kubernetes - 部署 - 配置 livenessProbe
- java - 有没有更好的方法用 Java 流映射映射值?
- rest - 如何使用 Tyk API 管理(或任何其他 API 网关)保护内部 API?
- c# - c# Substitution Cipher解密
- angular - 带有 Angular 6 的 Bootstrap 4 轮播 - ngFor 中的 Ol 链接
- css - 获取自定义模板目录的正确方法
- mysql - 将数据从 csv 导入 mariaDB 缺少第一列
- f# - 在 F# 中链接 string.replace
- android - 如何使用 Android Studio 通过 wifi 进行调试