Fix: add retry loop for Matrix UserID resolution to prevent M_INVALID_PARAM

This commit is contained in:
unfunny
2026-09-13 15:20:12 -04:00
parent a33f99cda2
commit 18f36a7c5f

View File

@@ -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) => {