Advertisement
code8exe

Untitled

Jun 6th, 2024
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.20 KB | None | 0 0
  1. import telebot
  2. import logging
  3.  
  4. # Настройка логирования
  5. logging.basicConfig(level=logging.DEBUG)
  6.  
  7. # Ваш токен бота
  8. bot_token = 'ВАШ ТОКЕН API'
  9. bot = telebot.TeleBot(bot_token)
  10.  
  11. # Функция для обработки команды /start
  12. @bot.message_handler(commands=['start'])
  13. def send_welcome(message):
  14. try:
  15. bot.reply_to(message, "Привет! Ваш chat_id: " + str(message.chat.id))
  16. logging.debug(f'Received start command from chat ID: {message.chat.id}')
  17. except Exception as e:
  18. logging.error(f'Error in send_welcome: {e}')
  19.  
  20. # Функция для обработки текстовых сообщений
  21. @bot.message_handler(content_types=['text'])
  22. def handle_text(message):
  23. try:
  24. chat_id = message.chat.id
  25. bot.send_message(chat_id, f"Ваш chat_id: {chat_id}")
  26. logging.debug(f'Received text from chat ID: {chat_id}')
  27. except Exception as e:
  28. logging.error(f'Error in handle_text: {e}')
  29.  
  30. if __name__ == "__main__":
  31. logging.debug('Bot is polling...')
  32. try:
  33. bot.polling(none_stop=True)
  34. except Exception as e:
  35. logging.error(f'Error in polling: {e}')
  36.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement