RocketChat/Rocket.Chat · error
User not found
Error message
User not found
What it means
Users.findOneByUsernameIgnoringCase(data.username) found no user, so the ban target does not exist. Username (not user id or display name) is the lookup key and must match a current username case-insensitively.
Source
Thrown at apps/meteor/server/lib/banUserFromRoom.ts:33
const room = await Rooms.findOneById(data.rid);
if (!room || !(await roomCoordinator.getRoomDirectives(room.t).allowMemberAction(room, RoomMemberActions.BAN, fromId))) {
throw new Error('Not allowed');
}
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);
View on GitHub (pinned to b2c16d5842)
Solutions
- Resolve the user first (users.info?username=...) and submit the canonical username
- Offer username autocomplete instead of free-text entry
- Handle 'User not found' distinctly from 'Not allowed' in the UI
Defensive patterns
Strategy: validation
Validate before calling
const { user } = await GET '/api/v1/users.info' { username };
if (!user) {
// no such username - do not call rooms.banUser
} Try / catch
try {
await POST '/api/v1/rooms.banUser' { roomId, username };
} catch (e) {
if (String(e.message).includes('User not found')) {
// resolve canonical username via users.info and retry once
} else {
throw e;
}
} Prevention
- Use username autocomplete instead of free-text ban targets
- Submit the canonical username (not display name or user id)
- Refresh user data before acting on old member lists
When it happens
Trigger: Typo in the username payload; the target renamed their username; a deleted or deactivated user; passing the display name or user id where username is expected.
Common situations: Hand-typed /ban slash commands; bots guessing usernames; UIs submitting stale usernames from an old member list.
Related errors
- Not allowed
- Invalid user
- The required "roomId" or "roomName" param provided does not
- User is not in this room
- User is already banned from this room
AI-assisted analysis of RocketChat/Rocket.Chat@b2c16d5842 (2026-08-18).
Data as JSON: /api/errors/517e0346c25062d5.
Report an issue: GitHub.