0
votes

Very new to coding so please be patient. I was wondering if it was possible to sort of nest commands and responses when dealing with a discord bot. For example, you'd use a command to see your options, then the bot would wait for a response to its message and reply accordingly. I'm having a little trouble describing what I mean so here's sort of an example: You ask the bot something The bot gives you options You choose from these options The bot responds to your answer or You ask the bot to do something with what you say next The bot asks you to say something You say something The bot uses what you've said in it's response

I've already tried nesting the on_message command into an already existing if statement but that obviously hasn't worked. I've also tried just adding another if statement, with the whole message.content stuff, hoping the bot would take the message after it's response into consideration.

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)

I was expecting the bot to take the message after it's reply into account but, the bot just starts from the beginning again.

1

1 Answers

0
votes

When the first command is entered, keep track of this fact using some sort of external state (for example, a global variable). You have the same on_message responding to the first command as the second, so it needs to look at that external state and decide what to do accordingly. A quick, off the cuff, not tested (because I don't have discord.py set up) example:

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.")