From 5ebab3a077846ffd7bb1fff98be67ee85dae7c39 Mon Sep 17 00:00:00 2001 From: Phxntxm Date: Sat, 17 Sep 2016 20:30:20 -0500 Subject: [PATCH] Added a check in case a message is not found when trying to delete; added a check to ensure the provided permission is valid --- cogs/mod.py | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/cogs/mod.py b/cogs/mod.py index 8d865e0..69acc00 100644 --- a/cogs/mod.py +++ b/cogs/mod.py @@ -165,6 +165,11 @@ class Mod: if permissions.lower() == "none": permissions = "send_messages" + # Check if the permission that was requested is valid + if getattr(discord.Permissions, permissions, None) is None: + await self.bot.say("{} does not appear to be a valid permission! Valid permissions are: ```\n{}```" + .format(permissions, "\n".join(valid_perms))) + return # Convert the string to an int value of the permissions object, based on the required permission perm_obj = discord.Permissions.none() setattr(perm_obj, permissions, True) @@ -203,11 +208,6 @@ class Mod: await self.bot.say("This command cannot have custom permissions setup!") return - if getattr(discord.Permissions, permissions, None) is None: - await self.bot.say("{} does not appear to be a valid permission! Valid permissions are: ```\n{}```" - .format(permissions, "\n".join(valid_perms))) - return - custom_perms = await config.get_content('custom_permissions') server_perms = custom_perms.get(ctx.message.server.id) or {} # Save the qualified name, so that we don't get screwed up by aliases @@ -299,8 +299,11 @@ class Mod: count = 0 async for msg in self.bot.logs_from(ctx.message.channel): if msg.author in members: - await self.bot.delete_message(msg) - count += 1 + try: + await self.bot.delete_message(msg) + count += 1 + except discord.NotFound: + pass if count >= limit: break msg = await self.bot.say("{} messages succesfully deleted".format(count))