samedi 25 mai 2019

Error with pictures and 'if' in Python TelegramBot. How to fix?

pyTelegramBotAPI Python 3.7

Bot in general works but an error occurs when the BOT should send the photo. When I write a bot message, in answer to which he must send a photo or a sticker, it goes but when next you enter the same command the bot sends nothing. I am a newbie so please suggest me how can I better write this code.

elif instead of if isn't working.

...
@bot.message_handler(content_types=["text"])

def bot_messages(message):
    if message.text.lower() == "Привет".lower():
        bot.send_message(message.from_user.id, "Ку! ✋. Напиши /welcome.")

    if message.text.lower() == "/welcome".lower():
        bot.send_message(message.from_user.id, "Я бот Римуру. Напиши название животного, например, 'кот', и я отправлю его картинку.")
        bot.send_sticker(message.from_user.id, sticker1)

    if message.text.lower() == "питон".lower():
        bot.send_photo(message.from_user.id, photo1)
    if message.text.lower() == "мышь".lower():
        bot.send_photo(message.from_user.id, photo2)
    if message.text.lower() == "кот".lower():
        bot.send_photo(message.from_user.id, photo3)
    if message.text.lower() == "жираф".lower():
...

Aucun commentaire:

Enregistrer un commentaire