{"record":{"id":"b4862858fdc7ac2c","repo":"RocketChat/Rocket.Chat","slug":"user-is-not-in-this-room","errorCode":null,"errorMessage":"User is not in this room","messagePattern":"User is not in this room","errorType":"exception","errorClass":null,"httpStatus":400,"severity":"error","filePath":"apps/meteor/server/lib/banUserFromRoom.ts","lineNumber":40,"sourceCode":"\tconst fromUser = await Users.findOneById(fromId);\n\tif (!fromUser) {\n\t\tthrow new Error('Invalid user');\n\t}\n\n\tif (!(await canAccessRoomAsync(room, fromUser))) {\n\t\tthrow new Error('The required \"roomId\" or \"roomName\" param provided does not match any group');\n\t}\n\n\tconst bannedUser = await Users.findOneByUsernameIgnoringCase(data.username);\n\tif (!bannedUser) {\n\t\tthrow new Error('User not found');\n\t}\n\n\tconst subscription = await Subscriptions.findOneByRoomIdAndUserId(data.rid, bannedUser._id, {\n\t\tprojection: { _id: 1, status: 1 },\n\t});\n\tif (!subscription) {\n\t\tthrow new Error('User is not in this room');\n\t}\n\n\t// Cannot ban a user who is already banned\n\tif (isBannedSubscription(subscription)) {\n\t\tthrow new Error('User is already banned from this room');\n\t}\n\n\t// Cannot ban the last owner\n\tif (await hasRoleAsync(bannedUser._id, 'owner', room._id)) {\n\t\tconst numOwners = await Roles.countUsersInRole('owner', room._id);\n\n\t\tif (numOwners === 1) {\n\t\t\tthrow new Error('You are the last owner. Please set new owner before banning the user.');\n\t\t}\n\t}\n\n\tawait banUserFromRoom(data.rid, bannedUser, fromUser);\n","sourceCodeStart":22,"sourceCodeEnd":58,"githubUrl":"https://github.com/RocketChat/Rocket.Chat/blob/b2c16d5842cbe6b69b59bdf6fc5e5f1afcd1f0b0/apps/meteor/server/lib/banUserFromRoom.ts#L22-L58","documentation":"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'.","triggerScenarios":"Banning a username who left the room; targeting a user who was kicked; pairing a rid with a username taken from a different room.","commonSituations":"Member lists stale after removals; automations banning from exported member lists; UI member caches out of date.","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"],"exampleFix":null,"handlingStrategy":"validation","validationCode":"const { members } = await GET '/api/v1/channels.members' { roomId }; // or groups.members / im.members\nif (!members.some((m) => m.username === username)) {\n  // target is not in the room - nothing to ban\n}","typeGuard":null,"tryCatchPattern":"try {\n  await POST '/api/v1/rooms.banUser' { roomId, username };\n} catch (e) {\n  if (String(e.message).includes('not in this room')) {\n    // target left or was removed - no ban needed (distinct from 'already banned')\n  } else {\n    throw e;\n  }\n}","preventionTips":["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"],"tags":["rocket-chat","rooms","moderation","subscriptions","membership"],"backgroundTag":"user-not-in-room","analyzedSha":"b2c16d5842cbe6b69b59bdf6fc5e5f1afcd1f0b0","analyzedAt":"2026-08-18T15:26:39.429Z","schemaVersion":2},"datasetVersion":"2026-08-21T13:17:26.733Z"}