How to simplify my Discord bot code for keyword detection

I need help making this Discord bot code cleaner and shorter. Python cares about uppercase and lowercase letters which makes my code repetitive. Can someone show me a better way to write this?

@bot.event
async def on_message(message):
    if 'Roberto' in message.content:
        print('Target word detected')
        await message.channel.send("not this again!")
    if 'roberto' in message.content:
        print('Target word detected')
        await message.channel.send("not this again!")
    if 'ROBERTO' in message.content:
        print('Target word detected')
        await message.channel.send("not this again!")

I have the same code repeated three times just to catch different cases of the same word. There must be a smarter way to handle this without writing so much duplicate code. What’s the best approach to make this work for any capitalization?

just convert the msg to lowercase with .lower(). like if 'roberto' in message.content.lower(): it saves ya lots of lines and covers all caps issues. way simpler!

Had this exact problem with my first Discord bot. The .lower() method works, but I’d go with .casefold() instead - it handles special characters and different languages way better. Try if 'roberto' in message.content.casefold(): if you’ve got international users. You can also throw your keywords into a set and check membership after converting to lowercase. Super handy when you’re watching multiple keywords since you don’t end up with crazy long if chains. Casefold’s a bit slower than lower, but it won’t matter for Discord bots unless you’re dealing with thousands of messages.

Converting to lowercase works, but here’s another option. Use regex with the re.IGNORECASE flag - it’s way more flexible for pattern matching. Just import re and use re.search(r'roberto', message.content, re.IGNORECASE) instead of basic string comparison. This really shines when you need to catch multiple keywords or complex patterns. Regex scales much better if you’re planning to expand your bot beyond simple word matching.