Untitled

mail@pastecode.io avatar
unknown
python
a year ago
1.3 kB
0
Indexable
Never
    @commands.command(name='reload', help='Reload modules')
    async def reload(self, message: commands.Context):
        if message.author.id == self.bot.ownerId:
            def error(ex):
                ex_type, ex_value, ex_traceback = sys.exc_info()
                trace_back = traceback.extract_tb(ex_traceback)
                stack_trace = list()
                for trace in trace_back:
                    stack_trace.append("File : %s , Line : %d, Func.Name : %s, Message : %s" % (
                        trace[0], trace[1], trace[2], trace[3]))
                return ex_type.__name__, ex_value, stack_trace

            errorGot = None
            for module in os.listdir('modules'):
                if module.endswith('.py'):
                    try:
                        await self.bot.reload_extension(f'modules.{module[:-3]}')
                    except Exception as e:
                        a, b, c = error(e)
                        errorGot = f'```bat\nException type : {a}\nException message : {b}\nStack trace : {c}\n```'
            if errorGot:
                await message.reply(f'Error:\n{errorGot}')
            else:
                os.system('cls')
                await message.reply('Done')