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

Why does the If statement not working with list[0]?

I am programming a Discord bot and it should have a birthday feature. I have some problem with the if statement and I just can’t figure out what could be wrong there. Can I even check the user input like that?

await ctx.send("What is your birthday? Please use MM/DD format.")

    msg = await self.bot.wait_for('message')
    try:
        date = msg.content.split('/')
        if date[0] > 12 or date[0] < 1:
            return await ctx.send(f"Aborting... Invalid date.")

    except:
        pass

>Solution :

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

you need to convert date[0] to be an int:

await ctx.send("What is your birthday? Please use MM/DD format.")

    msg = await self.bot.wait_for('message')
    try:
        date = msg.content.split('/')
        if int(date[0]) > 12 or int(date[0]) < 1:
            return await ctx.send(f"Aborting... Invalid date.")

    except:
        pass
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