2
votes

I'm a beginner to discord.py and struggling to find an answer to this. I want to make my discord bot respond to "message2" only after I send "message1". For example,

@client.event
async def on_message(message):
    if message.content.lower() == '!rps':
        await message.channel.send("Input your choice!")

Here I'd want the user to enter !rps which then I would wanna check his follow up response of rock/paper/scissors and let the bot reply accordingly. How do I make the bot wait for the user's next message after the user enters "!rps"

1

1 Answers

1
votes

You can make the bot to wait for the user input by wait_for function!

async def on_message(message):
    if message.content.lower() == '!rps':
        await message.channel.send("Input your choice!")
        def check(m):
            return m.content in ['rock','paper','scissors'] and m.channel == channel and m.author == message.author
        msg = await client.wait_for('message', check=check)
        #msg variable stores the new user input(rock/paper/scissors) [your code down]
        await channel.send(f'User Choosed {msg.content}')

In The above code i used wait_for function to wait for the user input! and with the help of check function i used to check if the input is valid and the input is made by the correct author n correct channel! if everything is valid, it start to execute the remaining code