Update DMChannel (#98)

* Update DMChannel: accept dm group

* Fix
This commit is contained in:
Nicolas 2022-08-07 01:07:02 -03:00 committed by GitHub
parent 76b9f0efe8
commit 406b09387c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -715,15 +715,30 @@ export abstract class BaseVoiceChannel extends GuildChannel {
export class DMChannel extends BaseChannel implements Model {
constructor(session: Session, data: DiscordChannel) {
super(session, data);
this.user = new User(this.session, data.recipents!.find(r => r.id !== this.session.botId)!);
this.type = data.type as ChannelTypes.DM | ChannelTypes.GroupDm;
if (data.owner_id && data.recipents) {
this.user = new User(session, data.recipents.find(user => user.id === data.owner_id)!);
} else {
this.user = new User(session, data.recipents!.find(user => user.id === this.session.botId)!);
}
if (data.recipents && data.recipents.length > 1) {
this.group = data.recipents.map(r => new User(this.session, r));
}
this.type = ChannelTypes.GroupDm | ChannelTypes.GroupDm;
if (data.last_message_id) {
this.lastMessageId = data.last_message_id;
}
}
override type: ChannelTypes.DM | ChannelTypes.GroupDm;
/** Onwer of the dm channel. */
user: User;
/** If the channel is a DM Group it's has multiple users. */
group?: User[];
/** Last message id. */
lastMessageId?: Snowflake;
async close(): Promise<DMChannel> {