RocketChat/Rocket.Chat · error · Meteor.Error
error-cant-invite-for-direct-room
error-cant-invite-for-direct-room
Error message
Can't invite user to direct rooms
What it means
Thrown by addUsersToRoomMethod() in apps/meteor/server/meteor-methods/rooms/addUsersToRoom.ts:57 when room.t === 'd' (direct room / DM) and the room is not a natively federated room (isRoomNativeFederated(room) === false). Direct rooms have fixed membership of exactly the two participants, so inviting additional users is structurally forbidden; only natively-federated DMs (which support extra Matrix participants) are exempt.
Source
Thrown at apps/meteor/server/meteor-methods/rooms/addUsersToRoom.ts:57
method: 'addUsersToRoom',
});
}
// Get user and room details
const room = await Rooms.findOneById(data.rid);
if (!room) {
throw new Meteor.Error('error-invalid-room', 'Invalid room', {
method: 'addUsersToRoom',
});
}
const subscription = await Subscriptions.findOneByRoomIdAndUserId(data.rid, userId, {
projection: { _id: 1 },
});
const userInRoom = subscription != null;
if (room.t === 'd' && !isRoomNativeFederated(room)) {
throw new Meteor.Error('error-cant-invite-for-direct-room', "Can't invite user to direct rooms", {
method: 'addUsersToRoom',
});
}
// Can add to any room you're in, with permission, otherwise need specific room type permission
let canAddUser = false;
if (userInRoom && (await hasPermissionAsync(userId, 'add-user-to-joined-room', room._id))) {
canAddUser = true;
} else if (room.t === 'c' && (await hasPermissionAsync(userId, 'add-user-to-any-c-room'))) {
canAddUser = true;
} else if (room.t === 'p' && (await hasPermissionAsync(userId, 'add-user-to-any-p-room'))) {
canAddUser = true;
}
// Adding wasn't allowed
if (!canAddUser) {
throw new Meteor.Error('error-not-allowed', 'Not allowed', {
method: 'addUsersToRoom',View on GitHub (pinned to b2c16d5842)
Solutions
- Filter out direct rooms before inviting: if (room.t === 'd') skip or surface a clear message.
- If a multi-user conversation is needed, create a new room (type 'p'/'c') or a discussion instead of adding to the DM.
- If Matrix-style multi-participant DMs are required, use natively federated rooms created through the federation flow.
- In custom UIs, disable/hide invite actions when the current room type is 'd'.
Example fix
// before
await addUsersToRoomMethod(uid, { rid, users });
// after
const room = await Rooms.findOneById(rid, { projection: { t: 1, federated: 1, federation: 1 } });
if (room?.t === 'd' && !isRoomNativeFederated(room)) {
throw new Error('cannot invite into a direct room; create a group instead');
}
await addUsersToRoomMethod(uid, { rid, users }); Defensive patterns
Strategy: validation
Validate before calling
const room = await Rooms.findOneById(rid, { projection: { t: 1, federated: 1, federation: 1 } });
if (room?.t === 'd' && !isRoomNativeFederated(room)) {
throw new Error('cannot invite into a direct room; create a group/discussion instead');
} Type guard
const isDirectRoom = (room: { t: string }): boolean => room.t === 'd'; Try / catch
try {
await addUsersToRoomMethod(uid, { rid, users });
} catch (e) {
if (e instanceof Meteor.Error && e.error === 'error-cant-invite-for-direct-room') {
// redirect the user: create a new group room with the desired members instead
}
} Prevention
- Hide invite actions for room type 'd' in UIs and bots.
- When adding a person to a conversation should scale beyond 1:1, create a 'p'/'c' room rather than mutating a DM.
- Filter rooms by type before running bulk invite scripts.
When it happens
Trigger: Calling the invite flow (addUsersToRoomMethod / 'addUserToRoom' / 'addUsersToRoom' methods, invite slash command paths) with the rid of a DM; front-end invite UI mistakenly enabled on direct rooms; code that loops over all rooms of a user and invites into DMs too.
Common situations: Bots or onboarding scripts inviting users into every room including DMs; UI state bugs where the invite dialog opens for room type 'd'; attempting to recreate group-chat behavior by 'adding' someone to an existing DM instead of creating a new group.
Related errors
AI-assisted analysis of RocketChat/Rocket.Chat@b2c16d5842 (2026-08-18).
Data as JSON: /api/errors/db2c26e6d61b3c6c.
Report an issue: GitHub.