Python 是否可以为discord bot嵌套命令?

Python 是否可以为discord bot嵌套命令?,python,discord,discord.py,Python,Discord,Discord.py,非常新的编码,所以请耐心等待。我想知道在处理一个不和谐的机器人时,是否有可能嵌套命令和响应。例如,您可以使用命令查看您的选项,然后bot将等待对其消息的响应,并相应地进行回复。我在描述我的意思时有点困难,所以这里有一个例子: 你问机器人什么 机器人给你选择 您可以从这些选项中进行选择 机器人会回应你的回答 或 你让机器人对你接下来说的话做点什么 机器人让你说些什么 你说什么 机器人会使用您在其响应中所说的内容 我已经尝试将on_message命令嵌套到一个已经存在的if语句中,但显然没有成功。我

非常新的编码,所以请耐心等待。我想知道在处理一个不和谐的机器人时,是否有可能嵌套命令和响应。例如,您可以使用命令查看您的选项,然后bot将等待对其消息的响应,并相应地进行回复。我在描述我的意思时有点困难,所以这里有一个例子: 你问机器人什么 机器人给你选择 您可以从这些选项中进行选择 机器人会回应你的回答 或 你让机器人对你接下来说的话做点什么 机器人让你说些什么 你说什么 机器人会使用您在其响应中所说的内容

我已经尝试将on_message命令嵌套到一个已经存在的if语句中,但显然没有成功。我还尝试添加另一个if语句,以及整个message.content的内容,希望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)

我希望bot在回复消息后会考虑该消息,但是,bot只是从头开始而已。

当输入第一个命令时,使用某种外部状态(例如,全局变量)跟踪这一事实。您对第一个命令的响应与对第二个命令的响应相同,因此它需要查看外部状态并决定相应的操作。一个快速、即兴、未经测试(因为我没有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.")