RocketChat/Rocket.Chat · error · Meteor.Error
error-user-is-banned
error-user-is-banned
Error message
User is banned from this room
What it means
Thrown inside the per-user loop of addUsersToRoomMethod() (apps/meteor/server/meteor-methods/rooms/addUsersToRoom.ts:101) when the target user already has a subscription for the room and isBannedSubscription(subscription) reports them as banned (subscription flagged with 'banned' role/marker from the ban flow, e.g. banUserFromRoom). Re-inviting a banned user is blocked; an unban must happen first. Like error-user-not-found, this rejects the entire Promise.all batch.
Source
Thrown at apps/meteor/server/meteor-methods/rooms/addUsersToRoom.ts:101
});
}
await beforeAddUsersToRoom.run({ usernames: data.users, inviter: user }, room);
await Promise.all(
data.users.map(async (username) => {
const sanitizedUsername = sanitizeUsername(username);
const newUser = await Users.findOneByUsernameIgnoringCase(sanitizedUsername);
if (!newUser) {
throw new Meteor.Error('error-user-not-found', 'User not found', {
method: 'addUsersToRoom',
});
}
const subscription = await Subscriptions.findOneByRoomIdAndUserId(data.rid, newUser._id);
if (subscription && isBannedSubscription(subscription)) {
throw new Meteor.Error('error-user-is-banned', 'User is banned from this room', {
method: 'addUsersToRoom',
});
}
if (!subscription) {
return addUserToRoom(data.rid, newUser, user);
}
if (!newUser.username) {
return;
}
void api.broadcast('notify.ephemeralMessage', userId, data.rid, {
msg: i18n.t('Username_is_already_in_here', {
username: newUser.username,
lng: user?.language,
}),
});
}),
);
View on GitHub (pinned to b2c16d5842)
Solutions
- Unban first: use the moderation flow (unban command or the unban endpoint), then invite again.
- Pre-check each target: const sub = await Subscriptions.findOneByRoomIdAndUserId(rid, userId); skip when isBannedSubscription(sub) and report them separately.
- Keep bulk jobs resilient: partition targets into 'invitable' vs 'banned' before calling so one banned user cannot reject the batch.
- Review whether the ban is still intended; if it is stale moderation data, unban to clear the flag.
Example fix
// before
await addUsersToRoomMethod(uid, { rid, users: ['alice', 'banned-bob'] }); // batch rejected
// after
const invitable: string[] = [];
for (const name of users) {
const u = await Users.findOneByUsernameIgnoringCase(sanitizeUsername(name), { projection: { _id: 1 } });
const sub = u && (await Subscriptions.findOneByRoomIdAndUserId(rid, u._id, { projection: { roles: 1 } }));
if (sub && isBannedSubscription(sub)) continue; // or: await unbanUserFromRoom(rid, u._id);
invitable.push(name);
}
await addUsersToRoomMethod(uid, { rid, users: invitable }); Defensive patterns
Strategy: validation
Validate before calling
const sub = await Subscriptions.findOneByRoomIdAndUserId(rid, targetUserId, { projection: { roles: 1 } });
if (sub && isBannedSubscription(sub)) {
// unban first or exclude from the batch
throw new Error('target is banned from this room; unban before inviting');
} Type guard
import { isBannedSubscription } from '@rocket.chat/core-typings';
// isBannedSubscription(subscription) is the canonical type guard for this state Try / catch
try {
await addUsersToRoomMethod(uid, { rid, users });
} catch (e) {
if (e instanceof Meteor.Error && e.error === 'error-user-is-banned') {
// unban the user via the moderation flow, then retry the invite
}
} Prevention
- Pre-filter bulk invite lists against subscriptions flagged as banned. Unban before re-inviting; never try to bypass the ban by direct DB writes. Keep moderation state visible to admins so stale bans get cleaned up.
When it happens
Trigger: Inviting a user who was banned from that channel via /ban or the moderation UI; their old subscription still exists carrying the banned flag; a bulk invite list containing previously banned members; banned user re-joining via invite link paths that route through this method.
Common situations: Moderation workflows where bans persist and an admin later tries to re-invite without unbanning; sync scripts replaying full member lists into rooms with bans; confusion between being banned (subscription flag) and having left (no subscription).
Related errors
- User is not in this room
- User is already banned from this room
- error-user-not-in-room
- error-user-not-in-room
- Room not found
AI-assisted analysis of RocketChat/Rocket.Chat@b2c16d5842 (2026-08-18).
Data as JSON: /api/errors/8ddc149a33d155a4.
Report an issue: GitHub.