[docs]classDiscordException(Exception):""" Base exception for discord_http """pass
[docs]classCheckFailed(DiscordException):""" Raised whenever a check fails """pass
[docs]classInvalidMember(CheckFailed):""" Raised whenever a user was found, but not a member of a guild """pass
[docs]classCommandOnCooldown(CheckFailed):def__init__(self,cooldown:Cooldown,retry_after:float):self.cooldown:Cooldown=cooldownself.retry_after:float=retry_aftersuper().__init__(f"Command is on cooldown for {retry_after:.2f}s")
[docs]classUserMissingPermissions(CheckFailed):""" Raised whenever a user is missing permissions """def__init__(self,perms:Permissions):self.permissions=permssuper().__init__(f"Missing permissions: {', '.join(perms.list_names)}")
[docs]classBotMissingPermissions(CheckFailed):""" Raised whenever a bot is missing permissions """def__init__(self,perms:Permissions):self.permissions=permssuper().__init__(f"Bot is missing permissions: {', '.join(perms.list_names)}")
[docs]classHTTPException(DiscordException):""" Base exception for HTTP requests """def__init__(self,r:"HTTPResponse"):self.request=rself.status:int=r.statusself.code:intself.text:strifisinstance(r.response,dict):self.code=r.response.get("code",0)self.text=r.response.get("message","Unknown")ifr.response.get("errors",None):self.text+=f"\n{r.response['errors']}"else:self.text:str=str(r.response)self.code=0error_text=f"HTTP {self.request.status} > {self.request.reason} (code: {self.code})"iflen(self.text):error_text+=f": {self.text}"super().__init__(error_text)
[docs]classNotFound(HTTPException):""" Raised whenever a HTTP request returns 404 """pass
[docs]classForbidden(HTTPException):""" Raised whenever a HTTP request returns 403 """pass
[docs]classAutomodBlock(HTTPException):""" Raised whenever a HTTP request was blocked by Discord """pass
[docs]classRatelimited(HTTPException):""" Raised whenever a HTTP request returns 429, but without a Retry-After header """pass
[docs]classDiscordServerError(HTTPException):""" Raised whenever an unexpected HTTP error occurs """pass