【问题标题】:How to take user message and use it as command如何获取用户消息并将其用作命令
【发布时间】:2019-11-25 07:17:26
【问题描述】:

我使用 Python 3 和 python-telegram-bot 。 用户发送这样的消息“当我说……说……”示例:“当我说嗨时说你好” 我可以从消息中获取“Hi and Hello” 我的问题是当用户打招呼我的机器人打招呼时如何在 bot 中设置 Hi

我尝试使用 MessageHandler 例如:

MessageHandler(Variable,Callback) 

变量有 hi 例如 但是当我发送你好时,我的机器人不会发送你好

但是当我发送你好时,我的机器人不发送你好

【问题讨论】:

    标签: python python-3.x telegram python-telegram-bot


    【解决方案1】:

    嗯,你可以使用一个事件。 on_message 应该可以工作。试试这个:(重写)

    bot.msg = "Hi" #just create a command in which you would assign a text to bot.msg
    
       @bot.listen()
        async def on_message(message):
            if message.content.lower() == bot.msg.lower()   #you can set a bot variable, I'll use `bot.msg`
        await message.channel.send("Hello")
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2022-08-14
      • 2021-08-15
      • 2020-10-30
      • 1970-01-01
      • 2021-08-02
      • 2022-06-25
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多