From b0ec22065e59d7fcce190333d2fa5b3de88b0e8b Mon Sep 17 00:00:00 2001 From: Rapptz Date: Sat, 1 May 2021 13:16:57 -0400 Subject: [PATCH] Add Client.create_dm --- discord/client.py | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/discord/client.py b/discord/client.py index 71e4bf6b9..7b361f162 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)