Ejemplo n.º 1
0
def handle_exception(event, bot, exception):
    # catch everything and extract all info we can from the func arguments so we see what exactly was going on
    print("Exception caught, extracting information")

    print("====EXCEPTION====")
    print(exception)

    print("====STACKTRACE====")
    print(traceback.format_exc())

    print("====ORIGINAL MESSAGE====")
    print(event.msg.content)

    print("====SENDER====")
    print(event.msg.author)

    print("====Channel====")
    print("{} ({})".format(event.msg.channel.name, event.msg.channel.id))

    embed = MessageEmbed()
    embed.title = "Exception caught"
    embed.add_field(name="Original message",
                    value=Utils.trim_message(event.msg.content, 1024))
    embed.add_field(name="Channel",
                    value="{} ({})".format(event.msg.channel.name,
                                           event.msg.channel.id))
    embed.add_field(name="Sender", value=str(event.msg.author))
    embed.add_field(name="Exception", value=str(exception))
    parts = Pages.paginate(str(traceback.format_exc()), max_chars=1024)
    if len(parts) > 4:
        embed.add_field(
            name="Stacktrace",
            value=
            "Something went incredibly wrong, stacktrace is over 4096 chars!")
    else:
        for part in parts:
            embed.add_field(name="Stacktrace", value=part)
    embed.timestamp = datetime.utcnow().isoformat()
    embed.color = int('ff0000', 16)
    log_to_bot_log(bot, embed=embed)