mirror of
https://github.com/python-telegram-bot/python-telegram-bot.git
synced 2024-12-22 22:45:09 +01:00
Change error handler example to work without developer chat id
This commit is contained in:
parent
fdf8124965
commit
c4efea6f38
1 changed files with 5 additions and 6 deletions
|
@ -18,12 +18,9 @@ logging.basicConfig(format='%(asctime)s - %(name)s - %(levelname)s - %(message)s
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
# this can be your own ID, or one for a developer group/channel
|
|
||||||
DEVELOPER_CHAT_ID = 208589966
|
|
||||||
|
|
||||||
|
|
||||||
def error_handler(update: Update, context: CallbackContext):
|
def error_handler(update: Update, context: CallbackContext):
|
||||||
"""Log the error and send a telegram message to notify the developer."""
|
"""Log the error and send a telegram message with error details."""
|
||||||
# Log the error before we do anything else, so we can see it even if something breaks.
|
# Log the error before we do anything else, so we can see it even if something breaks.
|
||||||
logger.error(msg="Exception while handling an update:", exc_info=context.error)
|
logger.error(msg="Exception while handling an update:", exc_info=context.error)
|
||||||
|
|
||||||
|
@ -47,8 +44,10 @@ def error_handler(update: Update, context: CallbackContext):
|
||||||
html.escape(tb)
|
html.escape(tb)
|
||||||
)
|
)
|
||||||
|
|
||||||
# Finally, send the message
|
# Finally, send the message. You can replace this with something like
|
||||||
context.bot.send_message(chat_id=DEVELOPER_CHAT_ID, text=message, parse_mode=ParseMode.HTML)
|
# context.bot.send_message(chat_id=DEVELOPER_CHAT_ID, text=message, parse_mode=ParseMode.HTML)
|
||||||
|
# to send the message to the bot developer rather than the user.
|
||||||
|
update.effective_message.reply_text(text=message, parse_mode=ParseMode.HTML)
|
||||||
|
|
||||||
|
|
||||||
def bad_command(update: Update, context: CallbackContext):
|
def bad_command(update: Update, context: CallbackContext):
|
||||||
|
|
Loading…
Reference in a new issue