コード例 #1
0
    def log(self, msg):                     #! funciton for logging if developer mode is on
        debug_info = gen.db_receive("var")
        try:
            debug_info["cogs"][self.qualified_name]
        except:
            debug_info["cogs"][self.qualified_name] = debug_info["DEV"]
            gen.db_update("var",debug_info)

        if debug_info["cogs"][self.qualified_name] == 1:
            if self.qualified_name in gen.cog_colours:
                return gen.error_message(msg, gen.cog_colours[self.qualified_name])
            else:
                return gen.error_message(msg, gen.cog_colours["default"])
コード例 #2
0
async def on_command_error(ctx, error: discord.DiscordException):

    if isinstance(error, commands.CommandNotFound):
        #await ctx.send(">>> That isn't even a command, you have again proven to be a ME!stake.", delete_after=5)
        pass

    elif isinstance(error, commands.CommandOnCooldown):
        embed = discord.Embed(
            title="Woah woah, gonnae wait??",
            color=discord.Color.red(),
            description=
            f"We have cooldowns here, try again after `{round(error.retry_after, 1)}s` "
        )
        await ctx.send(embed=embed)

    elif isinstance(error, commands.MissingPermissions):
        embed = discord.Embed(title="Missing Permissions",
                              color=discord.Color.red())

        description = "You are missing the following permsissions\n"
        for num, perm in enumerate(error.missing_perms):
            description += f"\n{num}. `{perm}`"
        description += "\n\n You can go beg the mods for them or something idk."

        embed.description = description

        await ctx.send(embed=embed)

    elif isinstance(error, commands.MissingRequiredArgument):
        pass

    elif isinstance(error, commands.CheckFailure):
        pass

    else:
        trace = traceback.format_exception(type(error), error,
                                           error.__traceback__)

        with open(LOG_FILE, "r+") as log_file:
            content = log_file.read()
            log_file.seek(0, 0)
            log_file.write(
                f"\n\n\nException occured on {str(datetime.now(tz=gen.TIMEZONE))} => \n"
            )
            log_file.writelines(trace)
            log_file.write(content)

        gen.error_message(error)
コード例 #3
0
 def log(self, msg):  # ! funciton for logging if developer mode is on
     cog_name = os.path.basename(__file__)[:-3]
     debug_info = gen.db_receive("var")["cogs"]
     try:
         debug_info[cog_name]
     except:
         debug_info[cog_name] = 0
     if debug_info[cog_name] == 1:
         return gen.error_message(msg, gen.cog_colours[cog_name])