diff --git a/bot.py b/bot.py index ff1aeaf..29ff527 100644 --- a/bot.py +++ b/bot.py @@ -3,6 +3,8 @@ import os import codecs import discord import time +import sys +import traceback from discord.ext import commands from cogs.utils.settings import Settings @@ -28,11 +30,12 @@ def _get_prefix(bot, message): class Bot(commands.Bot): - def __init__(self): + def __init__(self, debug: bool=False): super().__init__(command_prefix=_get_prefix, description=config["description"]) self.settings = Settings(**config) + self.debug = debug for extension in initial_extension: try: @@ -41,33 +44,40 @@ class Bot(commands.Bot): print(e) async def on_command_error(self, ctx, err): - if (isinstance(err, commands.MissingRequiredArgument) or - isinstance(err, commands.BadArgument)): - formatter = ctx.bot.formatter - if ctx.invoked_subcommand is None: - _help = await formatter.format_help_for(ctx, ctx.command) - else: - _help = await formatter.format_help_for(ctx, - ctx.invoked_subcommand) + if not self.debug: + if (isinstance(err, commands.MissingRequiredArgument) or + isinstance(err, commands.BadArgument)): + formatter = ctx.bot.formatter + if ctx.invoked_subcommand is None: + _help = await formatter.format_help_for(ctx, ctx.command) + else: + _help = await formatter.format_help_for(ctx, + ctx.invoked_subcommand) - for message in _help: - await ctx.send(message) + for message in _help: + await ctx.send(message) - if isinstance(err, commands.CommandInvokeError): - pass + if isinstance(err, commands.CommandInvokeError): + pass - elif isinstance(err, commands.NoPrivateMessage): - await ctx.send("Denne kommandoen er ikke tilgjengelig i DMs") + elif isinstance(err, commands.NoPrivateMessage): + await ctx.send("Denne kommandoen er ikke tilgjengelig i DMs") - elif isinstance(err, commands.CheckFailure): - pass + elif isinstance(err, commands.CheckFailure): + pass - elif isinstance(err, commands.CommandNotFound): - pass + elif isinstance(err, commands.CommandNotFound): + pass + else: + tb = err.__traceback__ + traceback.print_tb(tb) + print(err) async def on_ready(self): if not hasattr(self, 'uptime'): self.uptime = time.time() + if self.debug: + print('\n\nDebug mode') print(f'\nLogged in as: {self.user.name}' + f' in {len(self.guilds)} servers.') @@ -84,9 +94,12 @@ class Bot(commands.Bot): print('ifkn', e) -def run_bot(): - bot = Bot() +def run_bot(debug: bool=False): + bot = Bot(debug=debug) bot.run() if __name__ == '__main__': - run_bot() + if 'debug' in sys.argv: + run_bot(debug=True) + else: + run_bot(debug=False)