From 9a6390b9bdbb6eb7e3ea6360619a2879ce42cbe1 Mon Sep 17 00:00:00 2001 From: Madeline <46743919+MaddyUnderStars@users.noreply.github.com> Date: Wed, 12 Apr 2023 21:03:49 +1000 Subject: Fix DC client throwing on GUILD_CREATE --- src/util/dtos/ReadyGuildDTO.ts | 15 +++++++++++---- src/util/entities/Member.ts | 26 +++++++++++++++++--------- 2 files changed, 28 insertions(+), 13 deletions(-) (limited to 'src/util') diff --git a/src/util/dtos/ReadyGuildDTO.ts b/src/util/dtos/ReadyGuildDTO.ts index 2a99ea46..b21afe74 100644 --- a/src/util/dtos/ReadyGuildDTO.ts +++ b/src/util/dtos/ReadyGuildDTO.ts @@ -16,7 +16,14 @@ along with this program. If not, see . */ -import { Channel, Emoji, Guild, Member, Role, Sticker } from "../entities"; +import { + Channel, + Emoji, + Guild, + PublicMember, + Role, + Sticker, +} from "../entities"; export interface IReadyGuildDTO { application_command_counts?: { 1: number; 2: number; 3: number }; // ???????????? @@ -28,7 +35,7 @@ export interface IReadyGuildDTO { large: boolean | undefined; lazy: boolean; member_count: number | undefined; - members: Member[]; + members: PublicMember[]; premium_subscription_count: number | undefined; properties: { name: string; @@ -76,7 +83,7 @@ export class ReadyGuildDTO implements IReadyGuildDTO { large: boolean | undefined; lazy: boolean; member_count: number | undefined; - members: Member[]; + members: PublicMember[]; premium_subscription_count: number | undefined; properties: { name: string; @@ -127,7 +134,7 @@ export class ReadyGuildDTO implements IReadyGuildDTO { this.large = guild.large; this.lazy = true; // ?????????? this.member_count = guild.member_count; - this.members = guild.members; + this.members = guild.members?.map((x) => x.toPublicMember()); this.premium_subscription_count = guild.premium_subscription_count; this.properties = { name: guild.name, diff --git a/src/util/entities/Member.ts b/src/util/entities/Member.ts index cc2bf2a1..8c208202 100644 --- a/src/util/entities/Member.ts +++ b/src/util/entities/Member.ts @@ -330,17 +330,25 @@ export class Member extends BaseClassWithoutId { }); const memberCount = await Member.count({ where: { guild_id } }); - const memberPreview = await Member.find({ - where: { - guild_id, - user: { - sessions: { - status: Not("invisible" as const), // lol typescript? + + const memberPreview = ( + await Member.find({ + where: { + guild_id, + user: { + sessions: { + status: Not("invisible" as const), // lol typescript? + }, }, }, - }, - take: 10, - }); + relations: ["user", "roles"], + take: 10, + }) + ).map((member) => ({ + ...member.toPublicMember(), + user: member.user.toPublicUser(), + roles: member.roles.map((x) => x.id), + })); if ( await Member.count({ -- cgit 1.4.1