使用轮询的电报机器人没有给出任何响应

问题描述 投票:0回答:1

我在Python(3.7)中创建了一个Telegram bot来从网站上检索文章。我使用Python电报bot库中的start_polling()方法从用户那里获取命令,但是当我在命令行(Windows操作系统)中运行该文件时,根本没有响应。该文件继续运行并且不会终止,并且发送到机器人的任何消息都不会响应。代码段如下。

YOUR_TOKEN = secret!
WELCOME = 'Welcome!'


def brain_pickings():
  final_reply = pickings()
  bot.sendMessage(text=final_reply,parse_mode='html')


updater = Updater(token=YOUR_TOKEN)
dispatcher = updater.dispatcher
dispatcher.add_handler(CommandHandler('start', my_start))
dispatcher.add_handler(CommandHandler('brainpickings', brain_pickings))
updater.start_polling()
print('it is happening!')
updater.idle()
print('it is idle!')

机器人不会响应/启动或/取消。命令行上的输出(我输入了运行文件的命令):

C:\Users\ANJALI\.vscode\telegbot>python main.py
it is happening!

PS - pickings()是我定义用于检索文章的单独函数。它本身运行完美。如果需要在这里添加,请告诉我。

bots telegram telegram-bot python-3.7 python-telegram-bot
1个回答
0
投票

我让机器人运行了。我按照上面的评论中的建议尝试了日志记录,并且导入模块的方式出现了一些错误。否则代码就好了。

© www.soinside.com 2019 - 2024. All rights reserved.