Fix error on mute if user has role higher than bot

This commit is contained in:
Zeva Rose 2022-04-29 08:23:40 -06:00
parent 2a280b66b6
commit d0a0e3a456

View file

@ -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(