ArjunSharda / nextguild

Simplify interactions with the Guilded API
https://pypi.org/project/nextguild/
MIT License
5 stars 6 forks source link

Making a error event #11

Closed RaezDev1 closed 1 year ago

RaezDev1 commented 1 year ago

you really should add a @events.on_error async def on_error_example(error): bot.send_message(f"There is a new error {error}") so make something like that so every time there is a error it sends it to the channel and does not turn off the bot

erik-thorsell commented 1 year ago

Solution: use the module Logging to catch the errors and handle them your way.

Example:

import logging

# Configure the logging module
logging.basicConfig(filename='errors.log', level=logging.DEBUG, format='%(asctime)s %(levelname)s %(message)s')

@events.on_ready
async def on_ready():
    try:
        bot.send_message(nochannelgiven, "I'm online!")
    except Exception as e:
        logging.exception(e)