mirror of
https://github.com/eternnoir/pyTelegramBotAPI.git
synced 2023-08-10 21:12:57 +03:00
29 lines
682 B
Python
29 lines
682 B
Python
|
|
import telebot
|
|
from telebot.async_telebot import AsyncTeleBot
|
|
|
|
|
|
import logging
|
|
|
|
logger = telebot.logger
|
|
telebot.logger.setLevel(logging.DEBUG) # Outputs debug messages to console.
|
|
|
|
class ExceptionHandler(telebot.ExceptionHandler):
|
|
def handle(self, exception):
|
|
logger.error(exception)
|
|
|
|
bot = AsyncTeleBot('TOKEN',exception_handler=ExceptionHandler())
|
|
|
|
|
|
|
|
|
|
@bot.message_handler(commands=['photo'])
|
|
async def photo_send(message: telebot.types.Message):
|
|
await bot.send_message(message.chat.id, 'Hi, this is an example of exception handlers.')
|
|
raise Exception('test') # Exception goes to ExceptionHandler if it is set
|
|
|
|
|
|
|
|
import asyncio
|
|
asyncio.run(bot.polling())
|