Base
BaseObject
The base class for all cachable Discord entities
Attributes:
Name | Type | Description |
---|---|---|
state |
BaseState |
The state that the object belongs to |
id |
Optional[Snowflake|str] |
The object's unique identifier
provided by Discord's API, the will be the object's |
cached |
bool |
Whether or not the object is stored in its state's cache |
deleted |
bool |
Whether or not the object is deleted |
deleted_at |
Optional[datetime] |
The time at which the object was marked as deleted |
Warning
The deleted
and deleted_at
attributes will only be accurate
for objects maintained by a Discord WebSocket connection
__hash__(self)
special
Equivalent to hash(self.id)
Exceptions:
Type | Description |
---|---|
PartialObjectError |
Raised when the object's id is None |
Source code in snekcord\objects\baseobject.py
def __hash__(self):
"""Equivalent to `hash(self.id)`
Raises:
PartialObjectError: Raised when the object's id is None
"""
if self.id is None:
raise PartialObjectError(
f'{self.__class__.__name__} object is missing a valid id')
return hash(self.id)
cache(self)
Stores the object in the state's cache and attempts to remove it from the state's recycle bin
Source code in snekcord\objects\baseobject.py
def cache(self):
"""Stores the object in the state's cache and attempts
to remove it from the state's recycle bin
"""
self.cached = True
self.state[self.id] = self
self.state.unrecycle(self.id, None)
fetch(self)
async
Equivalent to self.state.fetch(self.id)
Source code in snekcord\objects\baseobject.py
async def fetch(self):
"""Equivalent to `self.state.fetch(self.id)`"""
return await self.state.fetch(self.id)
uncache(self, recycle=True)
Removes the object from the state's cache
Parameters:
Name | Type | Description | Default |
---|---|---|---|
recycle |
bool |
Whether or not to put the object in the state's recycle bin |
True |
Source code in snekcord\objects\baseobject.py
def uncache(self, recycle=True):
"""Removes the object from the state's cache
Arguments:
recycle bool: Whether or not to put the object in the
state's recycle bin
"""
self.cached = False
self.state.pop(self.id, None)
if recycle:
self.state.recycle(self.id, self)