Hello, i tried to edit the listener foncton to handle it for it can handle in case of an error, it found the attr but it doesnt edit the thing
@commands.Cog.listener()
async def on_cog_load(self):
for cog in self.bot.cogs.values():
for attr_name in dir(cog):
attr = getattr(cog, attr_name)
if callable(attr) and hasattr(attr, "__cog_listener__"):
wrapped_listener = self.listener_error_handle(attr)
setattr(cog, attr_name, wrapped_listener)
@staticmethod
def listener_error_handle(func):
@wraps(func)
async def wrapper(*args, **kwargs):
try:
return await func(*args, **kwargs)
except Exception as e:
logger.error(f"Error in {func.__name__}: {e}")
return wrapper
@commands.Cog.listener()
async def on_message(self, message):
if message.content == "error":
raise ValueError("This is a test error.")