From 18f36a7c5f2f7317e955e5c99a66e26ff373a348 Mon Sep 17 00:00:00 2001 From: unfunny Date: Sun, 13 Sep 2026 15:20:12 -0400 Subject: [PATCH] Fix: add retry loop for Matrix UserID resolution to prevent M_INVALID_PARAM --- index.js | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/index.js b/index.js index 1cb5e57..380548e 100644 --- a/index.js +++ b/index.js @@ -45,9 +45,26 @@ function loadQuotes() { console.log(`🏠 Server: ${server}`); try { + console.log('⏳ Connecting to Matrix...'); await client.startClient(); console.log('✅ MatrixClient connected and authenticated\n'); + // The M_INVALID_PARAM error often happens if we try to access properties + // before the user profile is fully loaded. + // Let's wait for the user identity to be available. + let attempts = 0; + while (!client.user || !client.user.userId) { + if (attempts > 15) { + throw new Error('Timeout waiting for Matrix UserID resolution.'); + } + console.log(`⏳ Waiting for User ID (Attempt ${attempts + 1})...`); + await new Promise(resolve => setTimeout(resolve, 2000)); + attempts++; + } + + console.log(`👤 Bot Identity: ${client.user.userId}`); + console.log(`🏠 Home Server: ${client.user.homeserver}`); + let lastSentMessage = null; client.on('RoomMember#joined', async (member) => {