From 3fcbe6ac878d1eaac10f334dadb997d6ceda5ea6 Mon Sep 17 00:00:00 2001 From: socram03 Date: Sun, 31 Jul 2022 22:15:32 -0400 Subject: [PATCH] feat: User.openDM() --- packages/core/src/structures/channels.ts | 6 ++++++ packages/core/src/structures/user.ts | 5 +++++ 2 files changed, 11 insertions(+) diff --git a/packages/core/src/structures/channels.ts b/packages/core/src/structures/channels.ts index d178487..f98dd25 100644 --- a/packages/core/src/structures/channels.ts +++ b/packages/core/src/structures/channels.ts @@ -685,6 +685,12 @@ export class DMChannel extends BaseChannel implements Model { return new DMChannel(this.session, channel); } + + async open(userId: Snowflake): Promise { + const channel = await this.session.rest.post(USER_DM(), { recipient_id: userId}); + + return new DMChannel(this.session, channel); + } } export interface DMChannel extends Omit, Omit {} diff --git a/packages/core/src/structures/user.ts b/packages/core/src/structures/user.ts index 84b4c69..76bc5ff 100644 --- a/packages/core/src/structures/user.ts +++ b/packages/core/src/structures/user.ts @@ -5,6 +5,7 @@ import type { DiscordUser, PremiumTypes, UserFlags } from '@biscuitland/api-type import type { ImageFormat, ImageSize } from '../utils/util'; import { USER, USER_AVATAR, USER_DEFAULT_AVATAR } from '@biscuitland/api-types'; import { Util } from '../utils/util'; +import { DMChannel } from './channels'; export type AvatarOptions = { format?: ImageFormat; @@ -113,6 +114,10 @@ export class User implements Model { return Util.formatImageURL(url, options.size ?? 128, options.format); } + openDM(): Promise { + return DMChannel.prototype.open.call({ session: this.session }, this.id); + } + toString(): string { return `<@${this.id}>`; }