Fix: add retry loop for Matrix UserID resolution to prevent M_INVALID_PARAM
This commit is contained in:
17
index.js
17
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) => {
|
||||
|
||||
Reference in New Issue
Block a user