Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Yes or no question with python on discord

I’m trying to make a Discord bot which can ask a yes-or-no question and respond to the user’s answer. I tried this code:

@bot.event
async def on_message(message):
    if message.content == 'ask me a question':
        await message.channel.send('Yes or No')
        if message.content == 'yes':
            await message.channel.send('correct!')
        elif message.content == 'no':
            await message.channel.send('wrong')

The bot responds to ‘ask me a question’, but when I type in ‘yes’ or ‘no’ I don’t get a response. Why doesn’t it work, and how can I fix it?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

The problem is you don’t ask it to wait for another message. Which means your variable message is still the "ask me a question" message. Intead, you should use bot.wait_for("message"), that will return the next message sent.

@bot.event
async def on_message(message):
    if message.content == 'ask me a question':
        await message.channel.send('Yes or No')

        response = await bot.wait_for("message")
        if response.content == 'yes':
            await message.channel.send('correct!')
        elif response.content == 'no':
            await message.channel.send('wrong')
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading