Answer the question
In order to leave comments, you need to log in
Telegram bot, response to the user if his message contains a word?
I'm trying to make a telegram bot, I need the bot to send a sticker to the user if his message contains a word, and does not match completely, how to implement this?
I am using pyTelegramBotAPI.
Example, the user sends a message, and if at least in some place of the message there is the word "Dima", a sticker is sent to the chat. Currently sending a sticker if the user's message consists only of "dima". Please help me figure it out. I can't find the answer for the life of me.
import telebot
import config
from telebot import types
bot = telebot.TeleBot(config.TOKEN)
@bot.message_handler(commands=['start'])
def welcome(message):
bot.send_message(message.chat.id, 'Hello' )
@bot.message_handler(content_types=['text'])
def lalala(message):
if message.text.lower() == 'dima' or message.text.lower() == 'dmitry' or message.text. lower() == 'dimon':
sti = open('stickers/sticker.webp', 'rb')
bot.send_sticker(message.chat.id, sti)
bot.polling(none_stop=True)
Answer the question
In order to leave comments, you need to log in
names = ['дима', 'дмитрий', 'димоооооон']
for name in names:
if name in message.text.lower():
# ваш код
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question