我们希望监控向机器人发送命令的用户,
但是当机器人启动时,
messagehandler能够捕获消息并报告私人聊天已启动,但它似乎无法捕获三个预定义命令中的任何一个(这些命令运行良好)。
这令人困惑。
下面是主要功能块。
提前谢谢。
def main() -> None:
"""Start the bot."""
# Create the Application and pass it your bot's token.
application = Application.builder().token("token").build()
# Command handlers
application.add_handler(CommandHandler('help', help_command))
application.add_handler(CommandHandler('start', start))
application.add_handler(CommandHandler('show_chats', show_chats))
# Handle members joining/leaving chats.
application.add_handler(ChatMemberHandler(greet_chat_members, ChatMemberHandler.CHAT_MEMBER))
# Keep track of which chats the bot is in
application.add_handler(ChatMemberHandler(track_chats, ChatMemberHandler.MY_CHAT_MEMBER))
# Interpret any other command or text message as a start of a private chat.
# This will record the user as being in a private chat with bot.
application.add_handler(MessageHandler(filters.ALL, start_private_chat))
# Run the bot until the user presses Ctrl-C
# We pass 'allowed_updates' handle *all* updates including `chat_member` updates
# To reset this, simply pass `allowed_updates=[]`
application.run_polling(allowed_updates=Update.ALL_TYPES)
如果我把命令处理程序放在消息处理程序后面,它们就不再工作了。