Answer the question
In order to leave comments, you need to log in
Telegram bot python. How to do if exactly the message that you asked was sent so that the bot responds?
Here is the code -
import telebot
import config
from telebot import types
bot = telebot.TeleBot(config.token)
@bot.message_handler(commands=['start'])
def start(m):
msg = bot.send_message(m.chat.id, 'Привет!')
keyboard = types.ReplyKeyboardMarkup(resize_keyboard=True)
keyboard.add(*[types.KeyboardButton(name) for name in ['Шерлок Холмс', 'Доктор Ватсон']])
bot.send_message(m.chat.id, 'Кого выбираешь?',
reply_markup=keyboard)
bot.register_next_step_handler(msg, name)
<b>
def name(m):
if m.text == 'Шерлок Холмс':
bot.send_message(m.chat.id, '*Ты выбрал Шерлока Холмса', parse_mode='Markdown')
elif m.text == 'Доктор Вастсон':
bot.send_message(m.chat.id, '*Ты выбрал Доктора Ватсона', parse_mode='Markdown')</b>
bot.polling()
Answer the question
In order to leave comments, you need to log in
@bot.message_handler(content_types=["text"])
def messages(message):
if 'шерлок' in message.text.lower() or 'холмс' in message.text.lower():
bot.send_message(message.chat.id, 'Вы выбрали Шерлока')
elif 'доктор' in message.text.lower() or 'ватсон' in message.text.lower():
bot.send_message(message.chat.id, 'Вы выбрали Ватсона')
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question