From d0a0e3a456a37f850aacb0ff1e7114ab51b7c9a8 Mon Sep 17 00:00:00 2001 From: Zevaryx Date: Fri, 29 Apr 2022 08:23:40 -0600 Subject: [PATCH] Fix error on mute if user has role higher than bot --- jarvis/cogs/admin/mute.py | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/jarvis/cogs/admin/mute.py b/jarvis/cogs/admin/mute.py index a8df321..b659265 100644 --- a/jarvis/cogs/admin/mute.py +++ b/jarvis/cogs/admin/mute.py @@ -6,6 +6,7 @@ from datetime import datetime, timedelta, timezone from dateparser import parse from dateparser_data.settings import default_parsers from dis_snek import InteractionContext, Permissions, Snake +from dis_snek.client.errors import Forbidden from dis_snek.models.discord.embed import EmbedField from dis_snek.models.discord.modal import InputText, Modal, TextStyles from dis_snek.models.discord.user import Member @@ -125,8 +126,11 @@ class MuteCog(ModcaseCog): f"`{old_until}` is in the past, which isn't allowed", ephemeral=True ) return - embed = await self._apply_timeout(ctx, ctx.target, reason, until) - await response.send(embed=embed) + try: + embed = await self._apply_timeout(ctx, ctx.target, reason, until) + await response.send(embed=embed) + except Forbidden: + await response.send("Unable to mute this user", ephemeral=True) @slash_command(name="mute", description="Mute a user") @slash_option(name="user", description="User to mute", opt_type=OptionTypes.USER, required=True) @@ -179,8 +183,11 @@ class MuteCog(ModcaseCog): return until = datetime.now(tz=timezone.utc) + timedelta(minutes=duration) - embed = await self._apply_timeout(ctx, user, reason, until) - await ctx.send(embed=embed) + try: + embed = await self._apply_timeout(ctx, user, reason, until) + await ctx.send(embed=embed) + except Forbidden: + await ctx.send("Unable to mute this user", ephemeral=True) @slash_command(name="unmute", description="Unmute a user") @slash_option(