mirror of
https://github.com/eternnoir/pyTelegramBotAPI.git
synced 2023-08-10 21:12:57 +03:00
Update
This commit is contained in:
27
examples/asynchronous_telebot/exception_handler.py
Normal file
27
examples/asynchronous_telebot/exception_handler.py
Normal file
@@ -0,0 +1,27 @@
|
||||
|
||||
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
|
||||
|
||||
|
||||
|
||||
bot.polling(skip_pending=True)
|
||||
Reference in New Issue
Block a user