Skip to content

"user_id or device_id mismatch" Error on Bot Startup #376

@aleksfolt

Description

@aleksfolt

When starting the bot built with the matrix-bot-sdk, an error occurs due to a mismatch between the user_id and device_id.

During the sync process, you’ll see this error message:

Thu, 13 Mar 2025 22:22:01 GMT [ERROR] [MatrixHttpClient] (REQ-3) {
'@botName:example.com': {
'-fmeqAf3': {
error: 'user_id or device_id mismatch: users: - @botName:example.com, devices: - -fmeqAf3'
}
}
}

code:

import {
    AutojoinRoomsMixin, ICryptoStorageProvider,
    LogLevel,
    LogService,
    MatrixClient,
    RichConsoleLogger, RustSdkCryptoStorageProvider,
    SimpleFsStorageProvider
} from "matrix-bot-sdk";
import * as path from "path";
import config from "./config.js";

LogService.setLogger(new RichConsoleLogger());
LogService.setLevel(LogLevel.DEBUG);

LogService.muteModule("Metrics");
LogService.info("index", "Bot starting...");


(async function () {
    const storage = new SimpleFsStorageProvider(path.join(config.dataPath, "bot.json"));

    const cryptoStore = new RustSdkCryptoStorageProvider(path.join(config.dataPath, "encrypted"));

    const client = new MatrixClient(config.homeserverUrl, config.accessToken, storage, cryptoStore);


    if (config.autoJoin) {
        AutojoinRoomsMixin.setupOnClient(client);
    }

    LogService.info("index", "Starting sync...");
    await client.start();
})();

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions