def load_module(self, module): try: self.load_extension("cogs.{}".format(module)) cOut("Loaded module: {}".format(module)) return True except Exception as e: cOut("Failed to load module {}: {}".format(module, e)) return False
def load_all(self): success, total = 0, 0 for i in [ f.replace(".py", "") for f in os.listdir("cogs") if os.path.isfile("cogs/" + f) ]: total += 1 if self.load_module(i): success += 1 cOut("Finished loading modules. ({}/{} Successful)".format( success, total))
async def sudo(self, ctx, user:discord.Member, *, cmd): sudo_msg = ctx.message if user is None: raise commands.BadArgument("Invalid user.") sudo_msg.author = user sudo_msg.content = cmd sudo_ctx = await self.bot.get_context(sudo_msg) response = await self.bot.invoke(sudo_ctx) cOut("SUDO: User '{0}' (ID {0.id}) executed '{1}' as '{2}' (ID {2.id}). RESULT: {3}".format(ctx.author, sudo_msg.content, sudo_ctx.author, response))
def __init__(self): super().__init__(command_prefix=None, description=bd.conf["description"]) if not os.path.isdir("cogs"): os.mkdir("cogs") try: print("\n-----") cOut("Starting bot session...") self.maintenance = False self.add_check(self.maintenance_mode) self.run(bd.conf["token"]) except discord.LoginFailure as e: cOut("Authentication error: {}".format(e)) # RESET TOKEN bd.conf["token"] = "" with open("config.json", "w") as f: json.dump(bd.conf, f, indent=4) raise end() except ClientConnectionError as e: cOut("Connection error: {}".format(e)) raise end() except Exception as e: cOut("Launch error: {}".format(e)) raise end()
async def on_ready(self): cOut("Bot is now accepting commands.\n-----") cOut("USERNAME: {}".format(self.user)) cOut("ID: {}".format(self.user.id)) cOut("Connected to {} guilds.\n-----".format(len(self.guilds))) self.load_all() self.startTime = time.time() self.loop.create_task(self.presence_changer())
async def on_resumed(self): cOut("Client has regained connection.")
async def on_disconnect(self): cOut("Client has lost connection.")
async def on_connect(self): cOut("Connection established with latency: {}ms".format( int(self.latency * 1000)))