Add error handling to unban
This commit is contained in:
parent
07975106ef
commit
23a5ac0849
1 changed files with 6 additions and 2 deletions
|
@ -4,6 +4,7 @@ from datetime import datetime, timedelta
|
|||
from logging import Logger
|
||||
|
||||
from dis_snek import Snake
|
||||
from dis_snek.client.errors import NotFound
|
||||
from jarvis_core.db import q
|
||||
from jarvis_core.db.models import Ban, Unban
|
||||
|
||||
|
@ -25,14 +26,17 @@ async def unban(bot: Snake, logger: Logger) -> None:
|
|||
user = await bot.fetch_user(ban.user)
|
||||
if guild and user:
|
||||
logger.debug(f"Unbanned user {user.id} from guild {guild.id}")
|
||||
await guild.unban(user=user, reason="JARVIS tempban expired")
|
||||
try:
|
||||
await guild.unban(user=user, reason="JARVIS tempban expired")
|
||||
except NotFound:
|
||||
logger.debug(f"User {user.id} not banned from guild {guild.id}")
|
||||
|
||||
ban.update(q(active=False))
|
||||
await ban.commit()
|
||||
u = Unban(
|
||||
user=user.id,
|
||||
guild=guild.id,
|
||||
username=user.name,
|
||||
username=user.username,
|
||||
discrim=user.discriminator,
|
||||
admin=bot.user.id,
|
||||
reason="Ban expired",
|
||||
|
|
Loading…
Add table
Reference in a new issue