RocketChat/Rocket.Chat · error
User is not in this room
Error message
User is not in this room
What it means
The target user exists but has no subscription document in the room (Subscriptions.findOneByRoomIdAndUserId empty) - they are not a member, so there is nothing to ban. A banned user keeps a subscription with status 'BANNED', so this error means 'never joined or already fully removed', not 'already banned'.
Source
Thrown at apps/meteor/server/lib/banUserFromRoom.ts:40
const fromUser = await Users.findOneById(fromId);
if (!fromUser) {
throw new Error('Invalid user');
}
if (!(await canAccessRoomAsync(room, fromUser))) {
throw new Error('The required "roomId" or "roomName" param provided does not match any group');
}
const bannedUser = await Users.findOneByUsernameIgnoringCase(data.username);
if (!bannedUser) {
throw new Error('User not found');
}
const subscription = await Subscriptions.findOneByRoomIdAndUserId(data.rid, bannedUser._id, {
projection: { _id: 1, status: 1 },
});
if (!subscription) {
throw new Error('User is not in this room');
}
// Cannot ban a user who is already banned
if (isBannedSubscription(subscription)) {
throw new Error('User is already banned from this room');
}
// Cannot ban the last owner
if (await hasRoleAsync(bannedUser._id, 'owner', room._id)) {
const numOwners = await Roles.countUsersInRole('owner', room._id);
if (numOwners === 1) {
throw new Error('You are the last owner. Please set new owner before banning the user.');
}
}
await banUserFromRoom(data.rid, bannedUser, fromUser);
View on GitHub (pinned to b2c16d5842)
Solutions
- Verify current membership (channels.members / groups.members / im.members) before banning
- Refresh member data before performing the action
- For private rooms note that non-members cannot rejoin without an invite, so a ban may be unnecessary
Defensive patterns
Strategy: validation
Validate before calling
const { members } = await GET '/api/v1/channels.members' { roomId }; // or groups.members / im.members
if (!members.some((m) => m.username === username)) {
// target is not in the room - nothing to ban
} Try / catch
try {
await POST '/api/v1/rooms.banUser' { roomId, username };
} catch (e) {
if (String(e.message).includes('not in this room')) {
// target left or was removed - no ban needed (distinct from 'already banned')
} else {
throw e;
}
} Prevention
- Verify membership from a live members list before banning
- Distinguish 'not in room' from 'already banned' when surfacing UI feedback
- For private rooms, non-members cannot rejoin uninvited - a ban is often unnecessary
When it happens
Trigger: Banning a username who left the room; targeting a user who was kicked; pairing a rid with a username taken from a different room.
Common situations: Member lists stale after removals; automations banning from exported member lists; UI member caches out of date.
Related errors
- User is already banned from this room
- error-invalid-subscription
- Not allowed
- The required "roomId" or "roomName" param provided does not
- You are the last owner. Please set new owner before banning
AI-assisted analysis of RocketChat/Rocket.Chat@b2c16d5842 (2026-08-18).
Data as JSON: /api/errors/b4862858fdc7ac2c.
Report an issue: GitHub.