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

Check for message content returns anything that includes the word

I need my bot to reply when someone says Hi or Hello, but when someone says a word including the letters ‘hi’ it will also respond to it, any way to fix this and tell the code to look for the exact word only? I’m using a very simple code ofcourse:

if message.content.startswith('hi') or message.content.startswith('hello'):
      #await message.reply("Hello Bro 🌹")

>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

split by spaces and check the first index. you’ll still have an issue with the bot responding to some who’s saying hi or hello to someone else, but it won’t trigger on other words.

if message.content.split(" ")[0] in ['hi', 'Hi', 'hello', 'Hello']:
    # respond

if you want more general check allowing for any capitalization (hI, hElLo, …)

if message.content.split(" ")[0].lower() in ['hi', 'hello']:
    # respond
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