From 64d5dcd53feccc25f176ed3fab45ad0de50b6367 Mon Sep 17 00:00:00 2001 From: dank074 Date: Wed, 9 Apr 2025 15:39:17 -0500 Subject: [PATCH 1/3] fix missing properties in GUILD_CREATE for bots --- src/gateway/opcodes/Identify.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/gateway/opcodes/Identify.ts b/src/gateway/opcodes/Identify.ts index c6f987fc..155dcb5a 100644 --- a/src/gateway/opcodes/Identify.ts +++ b/src/gateway/opcodes/Identify.ts @@ -455,13 +455,16 @@ export async function onIdentify(this: WebSocket, data: Payload) { }); // If we're a bot user, send GUILD_CREATE for each unavailable guild + // TODO: check if bot has permission to view some of these based on intents (i.e. GUILD_MEMBERS, GUILD_PRESENCES, GUILD_VOICE_STATES) await Promise.all( pending_guilds.map((x) => Send(this, { op: OPCODES.Dispatch, t: EVENTEnum.GuildCreate, s: this.sequence++, - d: x, + d: { + ...new ReadyGuildDTO(x).toJSON(), + }, })?.catch((e) => console.error(`[Gateway] error when sending bot guilds`, e), ), From f41164945e7ab2e400564de51f6d6c2d2b90ca5f Mon Sep 17 00:00:00 2001 From: dank074 Date: Wed, 9 Apr 2025 16:16:40 -0500 Subject: [PATCH 2/3] add type to make sure payload is consistent with other GUILD_CREATE event --- src/gateway/opcodes/Identify.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/gateway/opcodes/Identify.ts b/src/gateway/opcodes/Identify.ts index 155dcb5a..2798f3eb 100644 --- a/src/gateway/opcodes/Identify.ts +++ b/src/gateway/opcodes/Identify.ts @@ -32,6 +32,7 @@ import { DefaultUserGuildSettings, EVENTEnum, Guild, + GuildCreateEvent, GuildOrUnavailable, IdentifySchema, Intents, @@ -464,7 +465,7 @@ export async function onIdentify(this: WebSocket, data: Payload) { s: this.sequence++, d: { ...new ReadyGuildDTO(x).toJSON(), - }, + } as GuildCreateEvent["data"], })?.catch((e) => console.error(`[Gateway] error when sending bot guilds`, e), ), From fd33d58af83d9df9c37d345453cbb324f3b7a761 Mon Sep 17 00:00:00 2001 From: dank074 Date: Fri, 11 Apr 2025 18:39:45 -0500 Subject: [PATCH 3/3] revert back to original schema, but add missing `members` --- src/gateway/opcodes/Identify.ts | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/src/gateway/opcodes/Identify.ts b/src/gateway/opcodes/Identify.ts index 2798f3eb..4f1c7e2d 100644 --- a/src/gateway/opcodes/Identify.ts +++ b/src/gateway/opcodes/Identify.ts @@ -458,18 +458,31 @@ export async function onIdentify(this: WebSocket, data: Payload) { // If we're a bot user, send GUILD_CREATE for each unavailable guild // TODO: check if bot has permission to view some of these based on intents (i.e. GUILD_MEMBERS, GUILD_PRESENCES, GUILD_VOICE_STATES) await Promise.all( - pending_guilds.map((x) => - Send(this, { + pending_guilds.map((x) => { + //Even with the GUILD_MEMBERS intent, the bot always receives just itself as the guild members + const botMemberObject = members.find( + (member) => member.guild_id === x.id, + ); + + return Send(this, { op: OPCODES.Dispatch, t: EVENTEnum.GuildCreate, s: this.sequence++, d: { - ...new ReadyGuildDTO(x).toJSON(), - } as GuildCreateEvent["data"], + ...x.toJSON(), + members: botMemberObject + ? [ + { + ...botMemberObject.toPublicMember(), + user: user.toPublicUser(), + }, + ] + : [], + }, })?.catch((e) => console.error(`[Gateway] error when sending bot guilds`, e), - ), - ), + ); + }), ); // TODO: ready supplemental