create_dm_channel method

This commit is contained in:
grey-cat-1908 2022-03-18 12:13:46 +03:00
parent 59d5b51b0c
commit 3da683ebde
3 changed files with 15 additions and 2 deletions

View file

@ -1,6 +1,6 @@
from .models import User from .models import User
from .models.app import Shard from .models.app import Shard
from .utils import Snowflake from .utils import Snowflake, APIModelBase
from .utils.types import Coro from .utils.types import Coro
from .core.http import HTTPClient from .core.http import HTTPClient
@ -55,6 +55,8 @@ class Client:
self._activity = activity self._activity = activity
self._status = status self._status = status
APIModelBase.set_client(self)
async def _get_gateway(self): async def _get_gateway(self):
"""Get Gateway information""" """Get Gateway information"""
return GatewayBotInfo.from_dict(await self.http.get("gateway/bot")) return GatewayBotInfo.from_dict(await self.http.get("gateway/bot"))

View file

@ -194,3 +194,10 @@ class User(APIModelBase):
def avatar_url(self) -> str: def avatar_url(self) -> str:
"""Avatar url (from the Discord CDN server)""" """Avatar url (from the Discord CDN server)"""
return "https://cdn.discordapp.com/avatars/{}/{}.png?size=1024".format(self.id, self.avatar) return "https://cdn.discordapp.com/avatars/{}/{}.png?size=1024".format(self.id, self.avatar)
async def create_dm_channel(self):
# ToDo: Add docstrings
# ToDo: Add checking this channel in cache
return await self._http.post(
"/users/@me/channels", data={"recipient_id": self.id}
)

View file

@ -54,10 +54,14 @@ class APIModelBase:
@property @property
def _http(self): def _http(self):
if not self._client: if not self._client:
raise AttributeError("Object is not yet linked to a main client") return None
return self._client.http return self._client.http
@classmethod
def set_client(cls, client):
cls._client = client
@classmethod @classmethod
def from_dict( def from_dict(
cls: Generic[T], data: Dict[str, Union[str, bool, int, Any]] cls: Generic[T], data: Dict[str, Union[str, bool, int, Any]]