async def load(self, ctx, module: str): cog = "base_folder.bot.modules." + module try: self.client.load_extension(cog) except Exception as ex: e = error_embed(self.client) e.description = f"{cog} could not be loaded, here is the error:{ex}" await ctx.send(embed=e) e = success_embed(self.client) e.description = f"{cog} loaded" await ctx.send(embed=e)
async def on_command_error(self, ctx, ex): """ :param ctx: context of the command that caused the error :param ex: the exception itself :return: logs the error to the db if it wasn't a commands.* error and sends a log entry in the stdout channel regardless of the error """ if hasattr(ctx.command, 'on_error'): return error = getattr(ex, 'original', ex) embed = error_embed(self.client) print(error) # Printing the error for debugging reasons if isinstance(error, commands.CommandNotFound): embed.description = "I have never seen this command in my entire life" await ctx.send(embed=embed) return if isinstance(error, commands.errors.CheckFailure): embed.description = "You do not have permission to use this command." \ "If you think this is an error, talk to your admin" await ctx.send(embed=embed) return if isinstance(error, commands.BadArgument): embed.description = "You gave me an wrong input, check the command usage" await ctx.send(embed=embed) return if isinstance(error, commands.MissingRequiredArgument): embed.description = "You need to give the required arguments, check the command usage" await ctx.send(embed=embed) return if isinstance(error, commands.NoPrivateMessage): try: embed.description = "This command is for guilds/servers only" await ctx.author.send(embed=embed) except discord.Forbidden: pass return embed.description = "Something is totally wrong here in the M3E5 land I will open issue at my creator's bridge" await ctx.send(embed=embed) on_error.delay(ctx.guild.id, str(ex))
async def mute(self, ctx, member: discord.Member = None, reason="you made a mistake"): role = discord.utils.get(ctx.guild.roles, name="Muted") # retrieves muted role returns none if there isn't e = success_embed(self.client) e.description = f"{member.mention} was successfully muted for {reason}" if not role: # checks if there is muted role try: # creates muted role muted = await ctx.guild.create_role(name="Muted", reason="To use for muting") for channel in ctx.guild.channels: # removes permission to view and send in the channels await channel.set_permissions(muted, send_messages=False, read_message_history=False, read_messages=False) except discord.Forbidden: e = error_embed(self.client) e.description = f"Master please give me admin rights" return await ctx.send(embed=e) # self-explainatory await member.add_roles(muted) # adds newly created muted role await ctx.send(embed=e) else: await member.add_roles(role) # adds already existing muted role await ctx.send(embed=e) return e