Added a check in case a message is not found when trying to delete; added a check to ensure the provided permission is valid
This commit is contained in:
parent
85103727d6
commit
5ebab3a077
17
cogs/mod.py
17
cogs/mod.py
|
@ -165,6 +165,11 @@ class Mod:
|
||||||
if permissions.lower() == "none":
|
if permissions.lower() == "none":
|
||||||
permissions = "send_messages"
|
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
|
# Convert the string to an int value of the permissions object, based on the required permission
|
||||||
perm_obj = discord.Permissions.none()
|
perm_obj = discord.Permissions.none()
|
||||||
setattr(perm_obj, permissions, True)
|
setattr(perm_obj, permissions, True)
|
||||||
|
@ -203,11 +208,6 @@ class Mod:
|
||||||
await self.bot.say("This command cannot have custom permissions setup!")
|
await self.bot.say("This command cannot have custom permissions setup!")
|
||||||
return
|
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')
|
custom_perms = await config.get_content('custom_permissions')
|
||||||
server_perms = custom_perms.get(ctx.message.server.id) or {}
|
server_perms = custom_perms.get(ctx.message.server.id) or {}
|
||||||
# Save the qualified name, so that we don't get screwed up by aliases
|
# Save the qualified name, so that we don't get screwed up by aliases
|
||||||
|
@ -299,8 +299,11 @@ class Mod:
|
||||||
count = 0
|
count = 0
|
||||||
async for msg in self.bot.logs_from(ctx.message.channel):
|
async for msg in self.bot.logs_from(ctx.message.channel):
|
||||||
if msg.author in members:
|
if msg.author in members:
|
||||||
await self.bot.delete_message(msg)
|
try:
|
||||||
count += 1
|
await self.bot.delete_message(msg)
|
||||||
|
count += 1
|
||||||
|
except discord.NotFound:
|
||||||
|
pass
|
||||||
if count >= limit:
|
if count >= limit:
|
||||||
break
|
break
|
||||||
msg = await self.bot.say("{} messages succesfully deleted".format(count))
|
msg = await self.bot.say("{} messages succesfully deleted".format(count))
|
||||||
|
|
Loading…
Reference in a new issue