- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
想法是让电报机器人从用户那里接收一些数据,处理它,显示结果,然后重复整个循环而不等待用户的命令。这是代码:
from telebot import TeleBot
TOKEN = ""
bot = TeleBot(TOKEN)
@bot.message_handler(commands=['start'])
def regata(message):
bot.send_message(message.chat.id, 'Enter tmfs separated with space: ')
bot.register_next_step_handler(message, bla)
def bla(message):
data_from_tg = message.text.split()
tmf_1 = data_from_tg[0]
tmf_2 = data_from_tg[1]
bot.send_message(message.chat.id, f'Result: {tmf_1 + tmf_2}')
bot.register_next_step_handler(message, regata(message))
bot.polling()
所以机器人正在工作,但不幸的是,在将第二个结果发送给用户后,它失败了:
Traceback (most recent call last):
File "D:\python\bot\testbot.py", line 21, in <module>
bot.polling()
File "C:\Python39\lib\site-packages\telebot\__init__.py", line 664, in polling
self.__threaded_polling(non_stop, interval, timeout, long_polling_timeout, allowed_updates)
File "C:\Python39\lib\site-packages\telebot\__init__.py", line 726, in __threaded_polling
raise e
File "C:\Python39\lib\site-packages\telebot\__init__.py", line 686, in __threaded_polling
self.worker_pool.raise_exceptions()
File "C:\Python39\lib\site-packages\telebot\util.py", line 135, in raise_exceptions
raise self.exception_info
File "C:\Python39\lib\site-packages\telebot\util.py", line 87, in run
task(*args, **kwargs)
TypeError: 'NoneType' object is not callable
我是否需要使用其他一些 pytelegrambotapi 方法来实现这个想法?为什么两次都成功了,最后还是失败了?提前感谢您的任何想法。
最佳答案
试试这个:
@bot.message_handler(commands=['start'])
def regata(message):
msg = bot.send_message(message.chat.id, 'Enter tmfs separated with space: ')
bot.register_next_step_handler(msg, bla)
def bla(message):
data_from_tg = message.text.split()
tmf_1 = data_from_tg[0]
tmf_2 = data_from_tg[1]
msg = bot.send_message(message.chat.id, f'Result: {tmf_1 + tmf_2}')
regata(message)
bot.polling()
无论如何,我建议不要使用register_next_step_handler。您可以通过这种方式轻松地执行相同的操作:
@bot.message_handler(commands=['start'])
def regata(message):
bot.send_message(message.chat.id, 'Enter tmfs separated with space: ')
@bot.message_handler():
def bla(message):
data_from_tg = message.text.split()
tmf_1 = data_from_tg[0]
tmf_2 = data_from_tg[1]
bot.send_message(message.chat.id, f'Result: {tmf_1 + tmf_2}')
regata(message)
bot.polling()
关于python - 在电报机器人中使用 bot.register_next_step_handler 我得到 TypeError : 'NoneType' object is not callable,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/70502501/
是否可以将消息从 Telegram Bot 发送到另一个 Telegram Bot? 使用@botname 或直接将 botname 作为目标 ID 向另一个 bot 发送文本时,我收到错误响应。 我
早上好 我正在编写一个应用程序,需要通过 ATS 软件与 Verifone vx820 ped 进行通信。 在他们的文档中,为了传输数据,它指出: 我有一个关于如何执行此操作的 C# 示例,位于此处:
我对 Telegram API/TlDB 选项有点困惑。在电报文档中,说使用电报 API,您可以(以编程方式)执行用户作为应用程序可以执行的所有操作。 我使用了 Telethon (python) 库
如何向所有机器人用户发送消息? 有没有办法向所有人发送消息? 方法名称是什么? 最佳答案 来自 Official API FAQ : How can I message all of my bot's
我正在尝试从串行端口读取 MBUS 电报。我将串口中的所有内容都放入一个字节数组中。 每个 MBUS 电报都以这种模式(十六进制)开头:68 XX XX 68 其中 XX 是以字节为单位的电报长度。
我是创建电报机器人的新手,我真的不知道从哪里开始。我只知道 PHP。 为了简单起见,我有一个安装了 Windows Server 2008 R2 的 VPS,并且我使用了一个自签名证书 openssl
我正在尝试将 Telegraf 库与 Firebase Functions 结合使用,但它没有像我预期的那样工作。 我关注这些 this article和说明,如 webhooks (as appea
我正在分析电报或 whatsapp 等聊天应用程序。如您所知,他们正在使用到服务器的 tcp 连接。tcp 连接的最大问题是,当 internet 连接出现任何问题时,xmpp 客户端将与服务器断开连
我正在尝试每天向机器人发送消息,而无需从第二次对话开始从用户端(例如 commandhadler)触发。 我已经为机器人构建了一个与用户交互的基本菜单 但我也在尝试每天通过 job_queue 发送消
在我的代码中,我遇到了回调查询处理程序的问题,当我点击/start 命令时,“Next”按钮出现,当我点击该按钮时,它给我回复为“hi", 到这里输出是正确的。然后当我点击另一个命令“/help”然后
是否可以以管理员身份通过 API 向公共(public) Telegram channel 发送消息?我的意思是可以发送例如通过使用例如将视频发送到公共(public)电报 channel PHP?
我想将我的实时位置发送给电报机器人用户,机器人我收到此错误: ETELEGRAM: 400 Bad Request: there is no live location in the message
我需要帮助读取十六进制数据并应用公式来转换数据。我的文件用尾部解析: 2022-09-15 00:04:39 AAA99 BBB99 24 43 B2 50 2022-09-15 00:04:40 B
我需要帮助读取十六进制数据并应用公式来转换数据。我的文件用尾部解析: 2022-09-15 00:04:39 AAA99 BBB99 24 43 B2 50 2022-09-15 00:04:40 B
我在电报机器人中创建了新机器人,并执行如下步骤:- https://core.telegram.org/bots# 但是现在我需要当任何新用户加入我的机器人时,我需要向他展示欢迎信息。 怎么能这样?
电子表格包含项目 1,部署为具有以下权限的 Web 应用:执行身份:我,有权访问的人:任何人。 网络应用 function doPost(e) { myLog('Received from Add
我是一名优秀的程序员,十分优秀!