开发者社区 问答 正文

在Bot中获取用户的输入

我有一个关于使用python构建电报机器人的问题。如何从我的python-telegram-bot中获取用户的输入?

例如,字典机器人,我如何从用户那里得到一个单词?

展开
收起
游客6qcs5bpxssri2 2019-09-08 21:50:58 1396 分享 版权
1 条回答
写回答
取消 提交回答
  • 推荐回答

    使用python-telegram-bot v12.0.0b1,您可以这样做:

    def do_something(user_input):

    answer = "You have wrote me " + user_input
    
    return answer
    

    def reply(update, context):

    user_input = update.message.text
    
    update.message.reply_text(do_something(user_input))
    

    def main():

    updater = Updater("TOKEN", use_context=True)
    
    dp = updater.dispatcher
    
    dp.add_handler(MessageHandler(Filters.text, reply))
    
    updater.start_polling()
    
    updater.idle()
    
    2019-09-08 21:51:26
    赞同 展开评论
问答分类:
问答地址: