feat: User.openDM()

This commit is contained in:
socram03 2022-07-31 22:15:32 -04:00
parent 8f370d4c59
commit 3fcbe6ac87
2 changed files with 11 additions and 0 deletions

View File

@ -685,6 +685,12 @@ export class DMChannel extends BaseChannel implements Model {
return new DMChannel(this.session, channel); return new DMChannel(this.session, channel);
} }
async open(userId: Snowflake): Promise<DMChannel> {
const channel = await this.session.rest.post<DiscordChannel>(USER_DM(), { recipient_id: userId});
return new DMChannel(this.session, channel);
}
} }
export interface DMChannel extends Omit<TextChannel, 'type'>, Omit<BaseChannel, 'type'> {} export interface DMChannel extends Omit<TextChannel, 'type'>, Omit<BaseChannel, 'type'> {}

View File

@ -5,6 +5,7 @@ import type { DiscordUser, PremiumTypes, UserFlags } from '@biscuitland/api-type
import type { ImageFormat, ImageSize } from '../utils/util'; import type { ImageFormat, ImageSize } from '../utils/util';
import { USER, USER_AVATAR, USER_DEFAULT_AVATAR } from '@biscuitland/api-types'; import { USER, USER_AVATAR, USER_DEFAULT_AVATAR } from '@biscuitland/api-types';
import { Util } from '../utils/util'; import { Util } from '../utils/util';
import { DMChannel } from './channels';
export type AvatarOptions = { export type AvatarOptions = {
format?: ImageFormat; format?: ImageFormat;
@ -113,6 +114,10 @@ export class User implements Model {
return Util.formatImageURL(url, options.size ?? 128, options.format); return Util.formatImageURL(url, options.size ?? 128, options.format);
} }
openDM(): Promise<DMChannel> {
return DMChannel.prototype.open.call({ session: this.session }, this.id);
}
toString(): string { toString(): string {
return `<@${this.id}>`; return `<@${this.id}>`;
} }