RocketChat/Rocket.Chat · error · Meteor.Error

error-user-not-in-room

error-user-not-in-room

Error message

User is not in this room

What it means

addRoomModerator looks up the target's membership with Subscriptions.findOneByRoomIdAndUserId(rid, user._id); no subscription means the user is not in the room, so they cannot be made moderator. The role write attaches to the subscription document, so membership is a hard precondition.

Source

Thrown at apps/meteor/server/meteor-methods/rooms/addRoomModerator.ts:58

		});
	}

	if (isFederated && !isFederationEnabled()) {
		throw new FederationMatrixInvalidConfigurationError('unable to change room owners');
	}

	const user = await Users.findOneById(userId);

	if (!user?.username) {
		throw new Meteor.Error('error-invalid-user', 'Invalid user', {
			method: 'addRoomModerator',
		});
	}

	const subscription = await Subscriptions.findOneByRoomIdAndUserId(rid, user._id);

	if (!subscription) {
		throw new Meteor.Error('error-user-not-in-room', 'User is not in this room', {
			method: 'addRoomModerator',
		});
	}

	if (subscription.roles && Array.isArray(subscription.roles) === true && subscription.roles.includes('moderator') === true) {
		throw new Meteor.Error('error-user-already-moderator', 'User is already a moderator', {
			method: 'addRoomModerator',
		});
	}

	await beforeChangeRoomRole.run({ fromUserId, userId, room, role: 'moderator' });

	const addRoleResponse = await Subscriptions.addRoleById(subscription._id, 'moderator');
	await syncRoomRolePriorityForUserAndRoom(userId, rid, subscription.roles?.concat(['moderator']) || ['moderator']);

	if (addRoleResponse.modifiedCount) {
		void notifyOnSubscriptionChangedById(subscription._id);
	}

View on GitHub (pinned to b2c16d5842)

Solutions

  1. Invite the user to the room first (channels.invite / addUserToRoom), then promote.
  2. Re-check membership before offering the moderator action.
  3. On the error, refresh membership state instead of retrying blindly.
Defensive patterns

Strategy: try-catch

Validate before calling

// confirm membership before promoting
const sub = RocketChat.models?.Subscriptions?.findOne({ rid, 'u._id': userId });
if (!sub) {
	throw new Error('User is not in this room - invite first');
}

Try / catch

try {
	await Meteor.callAsync('addRoomModerator', rid, userId);
} catch (e: any) {
	if (e?.error === 'error-user-not-in-room') {
		// invite first (channels.invite), then retry the promotion
	}
}

Prevention

When it happens

Trigger: The target left/was removed from the room before the promotion; promoting a user who was never a member.

Common situations: Leave/join races with admin actions; unrefreshed member lists in moderation UIs.

Related errors


AI-assisted analysis of RocketChat/Rocket.Chat@b2c16d5842 (2026-08-18). Data as JSON: /api/errors/1ea5876a732cb213. Report an issue: GitHub.