trying to get a bot to send a photo using pytelegrambotapi but i keep do it just once

Viewed 12

I want my telegram bot written on Python using pyTelegramBotAPI to send a picture on command /photo If i try this code I will recive photo just once, no matter how many times I trigger ths command

photo = open('all_path/sudoku_1.png', 'rb')
@bot.message_handler(commands=['photo'])
def send_photo(message):
    bot.send_photo(message.chat.id,photo)

To receive it once more I have to restart the bot or do like that

@bot.message_handler(commands=['photo'])
def send_photo(message):
    bot.send_photo(message.chat.id, open('all_path/sudoku_1.png', 'rb'))

This is uncomfortable, can I do something else? And I'm new to Python and don't know much yet Help please

1 Answers

I don't see all your code, but maybe you didn't use bot.infinity_polling()??

It runs your bot until force stop, like while(True) loop.

Related