mirror of
https://github.com/MelisaDev/melisa.git
synced 2024-11-11 19:07:28 +03:00
create_dm_channel method
This commit is contained in:
parent
59d5b51b0c
commit
3da683ebde
3 changed files with 15 additions and 2 deletions
|
@ -1,6 +1,6 @@
|
|||
from .models import User
|
||||
from .models.app import Shard
|
||||
from .utils import Snowflake
|
||||
from .utils import Snowflake, APIModelBase
|
||||
from .utils.types import Coro
|
||||
|
||||
from .core.http import HTTPClient
|
||||
|
@ -55,6 +55,8 @@ class Client:
|
|||
self._activity = activity
|
||||
self._status = status
|
||||
|
||||
APIModelBase.set_client(self)
|
||||
|
||||
async def _get_gateway(self):
|
||||
"""Get Gateway information"""
|
||||
return GatewayBotInfo.from_dict(await self.http.get("gateway/bot"))
|
||||
|
|
|
@ -194,3 +194,10 @@ class User(APIModelBase):
|
|||
def avatar_url(self) -> str:
|
||||
"""Avatar url (from the Discord CDN server)"""
|
||||
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}
|
||||
)
|
||||
|
|
|
@ -54,10 +54,14 @@ class APIModelBase:
|
|||
@property
|
||||
def _http(self):
|
||||
if not self._client:
|
||||
raise AttributeError("Object is not yet linked to a main client")
|
||||
return None
|
||||
|
||||
return self._client.http
|
||||
|
||||
@classmethod
|
||||
def set_client(cls, client):
|
||||
cls._client = client
|
||||
|
||||
@classmethod
|
||||
def from_dict(
|
||||
cls: Generic[T], data: Dict[str, Union[str, bool, int, Any]]
|
||||
|
|
Loading…
Reference in a new issue