T
T
Tomorrow7722021-06-07 00:35:55
Python
Tomorrow772, 2021-06-07 00:35:55

Telegram bot not working?

Hello, why does the bot ignore the last 2 commands .....
What is the reason for this?
Although they should work .....
He answers the first 3 commands, and ignores the remaining 2, but there is no error in the console .....

import telebot

bot = telebot.TeleBot('тут был токен')


@bot.message_handler(commands=['start'])
def start(message):
    bot.reply_to(message, 'стартуем')

@bot.message_handler(commands=['help'])
def helpi(message):
    bot.send_message(message.chat.id, 'список команд:\n/start')

@bot.message_handler(content_types=["text"])
def skye(message):
    if message.text.lower() == 'бот':
    	bot.send_message(message.chat.id, 'Что-то хотели?')

@bot.message_handler(content_types=["text"])
def hello(message):
    if message.text.lower() == 'привет':
    	bot.send_message(message.chat.id, 'привет')

@bot.message_handler(content_types=["text"])
def God(message):
    	if message.text.lower() == 'Пока':
    		bot.send_message(message.chat.id, 'Пока')





bot.polling(none_stop=True)

Answer the question

In order to leave comments, you need to log in

3 answer(s)
S
Studentka1996, 2021-06-07
@Tomorrow772

Check if the condition is true, if not, then it is clear that the bot will not answer anything :)

O
Onigire, 2021-06-07
@Onigire

Why write a separate handler for each message? -_-
Why not...

@bot.message_handler(content_types=["text"])
def skye(message):
    if message.text.lower() == 'бот':
    	bot.send_message(message.chat.id, 'Что-то хотели?')
    elif message.text.lower() == 'привет':
    	bot.send_message(message.chat.id, 'привет')
    elif message.text.lower() == 'пока':      <-- тут "пока" с маленькой буквы
    	bot.send_message(message.chat.id, 'Пока')

And in the last handler you have extra indents.

S
soremix, 2021-06-07
@SoreMix

Because the handlers are the same, and only the first one works. If it's just a text response, then you can put everything in one function. If you need to separate large sections of code, then it makes sense to check the content in the handler:

@bot.message_handler(func=lambda m: m.text and m.text.lower() == 'привет')

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question