是否可以嵌套不和谐机器人的命令?

好吧

编码非常新,请耐心等待。我想知道在处理不和谐的机器人时是否有可能对嵌套命令和响应进行排序。例如,您将使用命令查看您的选项,然后该机器人将等待对其消息的响应并相应地回复。我在描述我的意思时遇到了一些麻烦,所以这里有一个例子:您向机器人询问一些东西机器人为您提供选项您可以从这些选项中选择机器人会回答您的回答,或者您让机器人对您的所作所为机器人说让你说些什么你说些什么机器人用你在回应中说的话

我已经尝试过将on_message命令嵌套到一个已经存在的if语句中,但这显然没有用。我还尝试过添加带有整个message.content内容的另一个if语句,希望bot在考虑到响应后才考虑该消息。

async def on_message(message):
    if message.author == client.user:
        return
    if message.content.startswith("!ml"):
        message.content = message.content.lower().replace(' ', '')
        if message.content in command1:
            response = "Hello! To start type !ml menu. You will be given your options. Don't forget to type !ml before " \
                       "everything you tell me, so I know it's me your talking to! Thanks : ) "
        elif message.content in command2:
            response = "test"
            if message.content in top:

            await message.channel.send(response)

我原以为该机器人会在收到回复后考虑该消息,但是,该机器人只是从头开始。

卡尔·克内希特尔

输入第一个命令后,请使用某种外部状态(例如,全局变量)来跟踪这一事实。on_message对第一个命令的响应与对第二个命令的响应相同,因此它需要查看该外部状态并决定相应地做什么。一个快速,简便的方法,未经测试(因为我没有设置discord.py)示例:

in_progress = False

async def on_message(message):
    if message.author == client.user:
        return
    elif "start" in message.content and not in_progress:
        in_progress = True
        await message.channel.send("You said `start`. Waiting for you to say `stop`.")
    elif "stop" in message.content and in_progress:
        in_progress = False
        await message.channel.send("You said `stop`. Waiting for you to `start` again.")

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章