From 046be93f9d06a0b9833b9475b609fc05972dd488 Mon Sep 17 00:00:00 2001 From: sgoudham Date: Sun, 9 Aug 2020 23:12:49 +0100 Subject: [PATCH] If user is already muted, send error message to prevent database from screwing up --- cogs/moderation.py | 49 ++++++++++++++++++++++++++-------------------- 1 file changed, 28 insertions(+), 21 deletions(-) diff --git a/cogs/moderation.py b/cogs/moderation.py index 2ab6ad8a..88e4bb50 100644 --- a/cogs/moderation.py +++ b/cogs/moderation.py @@ -123,32 +123,39 @@ async def mute_members(pool, ctx, targets, reason, muted): """ for target in targets: - if (ctx.message.guild.me.top_role.position > target.top_role.position - and not target.guild_permissions.administrator): + # When user is already muted, send error message + if muted in target.roles: + embed = Embed(description="**❌ User Is Already Muted! ❌**", + colour=enso_embedmod_colours) + await ctx.send(embed=embed) - # Store the current roles of the user within database - await storeRoles(pool=pool, target=target, ctx=ctx.message, member=target) - # Give the user the muted role - await target.edit(roles=[muted], reason=reason) + else: + if (ctx.message.guild.me.top_role.position > target.top_role.position + and not target.guild_permissions.administrator): - # Send confirmation to the channel that the user is in - embed = Embed(description="✅ **{}** Was Muted! ✅".format(target), - colour=enso_embedmod_colours) - if get_roles_persist(str(ctx.message.guild.id)) == 0: - embed.add_field(name="**WARNING: ROLE PERSIST NOT ENABLED**", - value="The bot **will not give** the roles back to the user if they leave the server." - " Allowing the user to bypass the Mute by leaving and rejoining." - f"\nPlease enable Role Persist by doing **{ctx.prefix}rolepersist enable**", - inline=True) + # Store the current roles of the user within database + await storeRoles(pool=pool, target=target, ctx=ctx.message, member=target) + # Give the user the muted role + await target.edit(roles=[muted], reason=reason) - await ctx.message.channel.send(embed=embed) + # Send confirmation to the channel that the user is in + embed = Embed(description="✅ **{}** Was Muted! ✅".format(target), + colour=enso_embedmod_colours) + if get_roles_persist(str(ctx.message.guild.id)) == 0: + embed.add_field(name="**WARNING: ROLE PERSIST NOT ENABLED**", + value="The bot **will not give** the roles back to the user if they leave the server." + " Allowing the user to bypass the Mute by leaving and rejoining." + f"\nPlease enable Role Persist by doing **{ctx.prefix}rolepersist enable**", + inline=True) - await send_to_modlogs(ctx.message, target, reason, action="Muted") + await ctx.message.channel.send(embed=embed) - # Send error message if the User could not be muted - else: - embed = Embed(description="**{} Could Not Be Muted!**".format(target.mention)) - await ctx.message.channel.send(embed=embed) + await send_to_modlogs(ctx.message, target, reason, action="Muted") + + # Send error message if the User could not be muted + else: + embed = Embed(description="**{} Could Not Be Muted!**".format(target.mention)) + await ctx.message.channel.send(embed=embed) async def ban_members(message, targets, reason):