aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRapptz <[email protected]>2021-05-01 13:16:57 -0400
committerRapptz <[email protected]>2021-05-01 13:16:57 -0400
commitb0ec22065e59d7fcce190333d2fa5b3de88b0e8b (patch)
tree7052cf94608b44aecf2e378a6c6c5e5bb3f516d0
parentFix supressing messages leading a 400 error (diff)
downloaddiscord.py-b0ec22065e59d7fcce190333d2fa5b3de88b0e8b.tar.xz
discord.py-b0ec22065e59d7fcce190333d2fa5b3de88b0e8b.zip
Add Client.create_dm
-rw-r--r--discord/client.py28
1 files changed, 28 insertions, 0 deletions
diff --git a/discord/client.py b/discord/client.py
index 71e4bf6b..7b361f16 100644
--- a/discord/client.py
+++ b/discord/client.py
@@ -1347,3 +1347,31 @@ class Client:
"""
data = await self.http.get_webhook(webhook_id)
return Webhook.from_state(data, state=self._connection)
+
+ async def create_dm(self, user):
+ """|coro|
+
+ Creates a :class:`.DMChannel` with this user.
+
+ This should be rarely called, as this is done transparently for most
+ people.
+
+ .. versionadded:: 2.0
+
+ Parameters
+ -----------
+ user: :class:`~discord.abc.Snowflake`
+ The user to create a DM with.
+
+ Returns
+ -------
+ :class:`.DMChannel`
+ The channel that was created.
+ """
+ state = self._connection
+ found = state._get_private_channel_by_user(user.id)
+ if found:
+ return found
+
+ data = await state.http.start_private_message(user.id)
+ return state.add_dm_channel(data)