1
Fork 0
mirror of https://github.com/wlinator/luminara.git synced 2024-10-02 18:03:12 +00:00

refactor: Improve error logging in xp handler

This commit is contained in:
wlinator 2024-09-01 12:19:23 -04:00
parent d9c2101e4b
commit d85619b671

View file

@ -5,6 +5,7 @@ import time
import discord
from discord.ext import commands
from loguru import logger
import lib.format
from lib.client import Luminara
@ -100,13 +101,12 @@ class XPHandler:
reason: str = "Automated Level Reward"
if role := self.guild.get_role(role_id):
with contextlib.suppress(
discord.Forbidden,
discord.NotFound,
discord.HTTPException,
):
try:
if isinstance(self.author, discord.Member):
await self.author.add_roles(role, reason=reason)
except (discord.Forbidden, discord.NotFound, discord.HTTPException) as e:
logger.error(f"Failed to add role {role_id} to {self.author.id}: {e}")
previous, replace = _rew.should_replace_previous_reward(_xp.level)
if (
@ -114,12 +114,10 @@ class XPHandler:
and isinstance(self.author, discord.Member)
and (role := self.guild.get_role(previous or role_id))
):
with contextlib.suppress(
discord.Forbidden,
discord.NotFound,
discord.HTTPException,
):
try:
await self.author.remove_roles(role, reason=reason)
except (discord.Forbidden, discord.NotFound, discord.HTTPException) as e:
logger.error(f"Failed to replace role {previous} with {role_id} from {self.author.id}: {e}")
async def get_level_channel(
self,