Python Forum
How to make a telegram bot respond to the specific word in a sentence?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to make a telegram bot respond to the specific word in a sentence?
#2
It's looking for any sequence of "lav" in the string. Here are two solutions.

1. Split the sentence up by white space. This will change the sentence to a list which you can iterate over, checking for the word.

sentence = message.text.lower()
if "lav" in sentence.split():
        bot.send_message(message.chat.id,  "Najgore pivo...")
2. Use a regular expression instead. "\blav\b" will do the trick.

import re

match_lav = re.compile("\blav\b")
matches = match_lav.findall(message.text.lower())

if len(matches) > 0:
        bot.send_message(message.chat.id,  "Najgore pivo...")
Reply


Messages In This Thread
RE: How to make a telegram bot respond to the specific word in a sentence? - by stullis - Dec-02-2019, 11:19 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  python print all files which contain specific word in it mg24 5 1,188 Jan-27-2023, 11:20 AM
Last Post: snippsat
Question Problem: Check if a list contains a word and then continue with the next word Mangono 2 2,455 Aug-12-2021, 04:25 PM
Last Post: palladium
  Use of respond.get ebolisa 2 1,712 Jul-31-2021, 02:11 PM
Last Post: ebolisa
  while sentence kimyyya 3 2,907 Mar-20-2021, 06:00 AM
Last Post: Pedroski55
  List / arrays putting in sentence Kurta 3 2,516 Dec-25-2020, 11:29 AM
Last Post: Larz60+
  Not able to make a specific thing pause in pygame cooImanreebro 4 3,145 Dec-13-2020, 10:34 PM
Last Post: cooImanreebro
  Searching for specific word in text files. JellyCreeper6 1 1,695 Nov-03-2020, 01:52 PM
Last Post: DeaD_EyE
  How to match partial sentence in long sentence Mekala 1 1,488 Jul-22-2020, 02:21 PM
Last Post: perfringo
  Python Speech recognition, word by word AceScottie 6 15,862 Apr-12-2020, 09:50 AM
Last Post: vinayakdhage
  Remove a sentence if it contains a word. lokhtar 6 5,775 Feb-11-2020, 04:43 PM
Last Post: stullis

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020