mirror of
https://github.com/Cog-Creators/Red-DiscordBot.git
synced 2025-11-06 11:18:54 -05:00
Allows cog creators to explain clearly why a cog cannot load by raising `redbot.core.errors.CogLoadError`. Instead of having to check in the console what's wrong, the message will directly be sent in the context channel.
24 lines
649 B
Python
24 lines
649 B
Python
import importlib.machinery
|
|
|
|
|
|
class RedError(Exception):
|
|
"""Base error class for Red-related errors."""
|
|
|
|
|
|
class PackageAlreadyLoaded(RedError):
|
|
"""Raised when trying to load an already-loaded package."""
|
|
|
|
def __init__(self, spec: importlib.machinery.ModuleSpec, *args, **kwargs):
|
|
super().__init__(*args, **kwargs)
|
|
self.spec: importlib.machinery.ModuleSpec = spec
|
|
|
|
def __str__(self) -> str:
|
|
return f"There is already a package named {self.spec.name.split('.')[-1]} loaded"
|
|
|
|
|
|
class CogLoadError(RedError):
|
|
"""Raised by a cog when it cannot load itself.
|
|
The message will be send to the user."""
|
|
|
|
pass
|