utils/restrictions.py: Catch exception when modifying roles of banned user.
@@ -102,6 +102,7 @@ class RestrictionsManager(BaseManager, db_manager=RestrictionsDatabaseManager):
TimedRestriction(restriction_id=now, user_id=user.id, type=restriction.value, end_date=end_date,
alerted=False))
if restriction is not Restriction.Ban and isinstance(user, discord.Member):
+ try:
await user.add_roles(self.bot.roles[restriction.value])
if restriction is Restriction.Muted:
await user.remove_roles(self.bot.roles['#elsewhere'], self.bot.roles['#art-discussion'])
@@ -113,6 +114,9 @@ class RestrictionsManager(BaseManager, db_manager=RestrictionsDatabaseManager):
if end_date:
msg_user += f"\n\nThis restriction lasts until {format_dt(end_date)}."
await send_dm_message(user, msg_user)
+ except discord.NotFound:
+ # User may have been banned
+ pass
return res
async def get_restrictions_by_type(self, restriction: Restriction):
