Advertisement
askanton

caption_telebot

Jun 19th, 2022
918
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.27 KB | None | 0 0
  1. import telebot  # Імпортуємо потрібні бібліотеки
  2. from telebot import types
  3. import time
  4. bot = telebot.TeleBot('**********:********************************')  # записуєм токен
  5.  
  6.  
  7. @bot.message_handler(content_types=['photo'])  # хендлер що реагує на фото
  8. def starting(message):
  9.     print(message)  # виводимо отриманне повідомлення в консоль
  10.     print("************************************************************")
  11.     if message.caption != None:
  12.         print(message.caption)
  13.  
  14.  
  15. @bot.message_handler(content_types=['text'])  # хендлер що реагує на текст
  16. def starting(message):
  17.     print(message)  # виводимо отриманне повідомлення в консоль
  18.     print("************************************************************")
  19.  
  20.  
  21. if __name__ == '__main__':  # Блок запуску бота
  22.     try:
  23.         bot.polling(none_stop=True)  # Запускаємо бота
  24.     except OSError:
  25.         print("PollingError - Sending again after 5 seconds!!!")  # виводимр помилку в конслоь
  26.         time.sleep(5)  # робимо паузу
  27.         bot.polling(none_stop=True)  # Запускаємо ботаа
  28.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement