-3

I'm struggling to get this code more simple but Python is case-sensitive a lot. Is there to turn this code cleaner????

@client.event
async def on_message(msg):
    if 'Marcelo' in msg.content:
        print('Keyword found in message')
        await msg.channel.send("oh this shit again!")
    if 'marcelo' in msg.content:
        print('Keyword found in message')
        await msg.channel.send("oh this shit again!")
    if 'MARCELO' in msg.content:
        print('Keyword found in message')
        await msg.channel.send("oh this shit again!")

1 Answers1

1

You could use <str>.lower, like this:

@client.event
async def on_message(msg):
    if 'marcelo' in msg.content.lower():
        print('Keyword found in message')

You also might not want to use the in keyword, as it means if you typed 'Hey Marcello', it would still output. I don't know if this is what you want, given the print statement, but most of the time it would make more sense to use msg.content.lower().startsWith('marcelo'), or msg.content.lower() == 'marcelo'

CATboardBETA
  • 418
  • 6
  • 29