summary refs log tree commit diff
diff options
context:
space:
mode:
authorV3L0C1T13S <51764975+V3L0C1T13S@users.noreply.github.com>2023-01-16 23:44:29 -0500
committerGitHub <noreply@github.com>2023-01-17 15:44:29 +1100
commit78df79df9dbd41e24210f76e3a8a761f80108391 (patch)
tree4049931d802a7d7a089d79fd0998fbdc87502512
parentFix deleting an application if it has a bot (diff)
downloadserver-78df79df9dbd41e24210f76e3a8a761f80108391.tar.xz
send GUILD_CREATE after READY event (#938)
* Fix lazy guilds being sent before READY event

* Make casing consistent
-rw-r--r--src/gateway/opcodes/Identify.ts22
1 files changed, 13 insertions, 9 deletions
diff --git a/src/gateway/opcodes/Identify.ts b/src/gateway/opcodes/Identify.ts
index 1c3cab28..b508cbf6 100644
--- a/src/gateway/opcodes/Identify.ts
+++ b/src/gateway/opcodes/Identify.ts
@@ -141,18 +141,11 @@ export async function onIdentify(this: WebSocket, data: Payload) {
 	}) as PublicMember[][];
 	let guilds = members.map((x) => ({ ...x.guild, joined_at: x.joined_at }));
 
+	const pending_guilds: typeof guilds = [];
 	// @ts-ignore
 	guilds = guilds.map((guild) => {
 		if (user.bot) {
-			setTimeout(() => {
-				var promise = Send(this, {
-					op: OPCODES.Dispatch,
-					t: EVENTEnum.GuildCreate,
-					s: this.sequence++,
-					d: guild,
-				});
-				if (promise) promise.catch(console.error);
-			}, 500);
+			pending_guilds.push(guild);
 			return { id: guild.id, unavailable: true };
 		}
 
@@ -314,6 +307,17 @@ export async function onIdentify(this: WebSocket, data: Payload) {
 		d,
 	});
 
+	await Promise.all(
+		pending_guilds.map((guild) =>
+			Send(this, {
+				op: OPCODES.Dispatch,
+				t: EVENTEnum.GuildCreate,
+				s: this.sequence++,
+				d: guild,
+			})?.catch(console.error),
+		),
+	);
+
 	//TODO send READY_SUPPLEMENTAL
 	//TODO send GUILD_MEMBER_LIST_UPDATE
 	//TODO send SESSIONS_REPLACE