Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import telebot
- import logging
- # Настройка логирования
- logging.basicConfig(level=logging.DEBUG)
- # Ваш токен бота
- bot_token = 'ВАШ ТОКЕН API'
- bot = telebot.TeleBot(bot_token)
- # Функция для обработки команды /start
- @bot.message_handler(commands=['start'])
- def send_welcome(message):
- try:
- bot.reply_to(message, "Привет! Ваш chat_id: " + str(message.chat.id))
- logging.debug(f'Received start command from chat ID: {message.chat.id}')
- except Exception as e:
- logging.error(f'Error in send_welcome: {e}')
- # Функция для обработки текстовых сообщений
- @bot.message_handler(content_types=['text'])
- def handle_text(message):
- try:
- chat_id = message.chat.id
- bot.send_message(chat_id, f"Ваш chat_id: {chat_id}")
- logging.debug(f'Received text from chat ID: {chat_id}')
- except Exception as e:
- logging.error(f'Error in handle_text: {e}')
- if __name__ == "__main__":
- logging.debug('Bot is polling...')
- try:
- bot.polling(none_stop=True)
- except Exception as e:
- logging.error(f'Error in polling: {e}')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement