Better group DM support.

This commit is contained in:
Rapptz
2017-02-09 20:47:47 -05:00
parent 926f01f0b6
commit ca81f0c3fc
3 changed files with 174 additions and 1 deletions

View File

@ -308,6 +308,45 @@ class ClientUser(BaseUser):
# manually update data by calling __init__ explicitly.
self.__init__(state=self._state, data=data)
@asyncio.coroutine
def create_group(self, *recipients):
"""|coro|
Creates a group direct message with the recipients
provided. These recipients must be have a relationship
of type :attr:`RelationshipType.friend`.
Bot accounts cannot create a group.
Parameters
-----------
\*recipients
An argument list of :class:`User` to have in
your group.
Return
-------
:class:`GroupChannel`
The new group channel.
Raises
-------
HTTPException
Failed to create the group direct message.
ClientException
Attempted to create a group with only one recipient.
This does not include yourself.
"""
from .channel import GroupChannel
if len(recipients) < 2:
raise ClientException('You must have two or more recipients to create a group.')
users = [str(u.id) for u in recipients]
data = yield from self._state.http.create_group(self.id, users)
return GroupChannel(me=self, data=data, state=self._state)
class User(BaseUser, discord.abc.Messageable):
"""Represents a Discord user.