Skip to main content

Overview

Baileys provides methods to configure various group settings. Only group admins can modify these settings.

Announcement Mode

Control who can send messages in the group.

Function Signature

groupSettingUpdate(
  jid: string,
  setting: 'announcement' | 'not_announcement' | 'locked' | 'unlocked'
): Promise<void>

Enable Announcement Mode

Only allow admins to send messages.
// Only admins can send messages
await sock.groupSettingUpdate(jid, 'announcement')
When announcement mode is enabled, regular members cannot send messages. Only admins can post to the group.

Disable Announcement Mode

Allow everyone to send messages.
// Allow everyone to send messages
await sock.groupSettingUpdate(jid, 'not_announcement')

Locked Settings

Control who can modify group settings like the display picture, name, and description.

Lock Group Settings

Only allow admins to modify group settings.
// Only allow admins to modify the group's settings
await sock.groupSettingUpdate(jid, 'locked')
When locked, only admins can change the group’s display picture, name, description, and other settings.

Unlock Group Settings

Allow everyone to modify group settings.
// Allow everyone to modify the group's settings
await sock.groupSettingUpdate(jid, 'unlocked')
When unlocked, any member can change the group picture, name, and description. This may lead to unwanted modifications.

Group Subject (Name)

Update the group’s name.

Function Signature

groupUpdateSubject(jid: string, subject: string): Promise<void>

Update Group Name

await sock.groupUpdateSubject(jid, 'New Subject!')

Example with Validation

const updateGroupName = async (groupJid: string, newName: string) => {
  // Validate name length (WhatsApp limits to 25 characters)
  if (newName.length > 25) {
    throw new Error('Group name cannot exceed 25 characters')
  }

  if (newName.trim().length === 0) {
    throw new Error('Group name cannot be empty')
  }

  try {
    await sock.groupUpdateSubject(groupJid, newName)
    console.log(`Group name updated to: ${newName}`)
  } catch (error) {
    console.error('Failed to update group name:', error)
    throw error
  }
}

Group Description

Update the group’s description.

Function Signature

groupUpdateDescription(jid: string, description?: string): Promise<void>

Set Description

await sock.groupUpdateDescription(jid, 'New Description!')

Remove Description

Pass undefined or an empty string to remove the description.
// Remove description
await sock.groupUpdateDescription(jid, undefined)

Complete Example

const updateGroupDescription = async (
  groupJid: string,
  description?: string
) => {
  try {
    await sock.groupUpdateDescription(groupJid, description)
    
    if (description) {
      console.log('Description updated')
    } else {
      console.log('Description removed')
    }
  } catch (error) {
    console.error('Failed to update description:', error)
    throw error
  }
}
The implementation automatically handles the previous description ID (descId) by fetching current metadata. This ensures proper description versioning.

Member Add Mode

Control who can add new members to the group.

Function Signature

groupMemberAddMode(
  jid: string,
  mode: 'admin_add' | 'all_member_add'
): Promise<void>

Only Admins Can Add

await sock.groupMemberAddMode(jid, 'admin_add')

All Members Can Add

await sock.groupMemberAddMode(jid, 'all_member_add')

Example Toggle Function

const toggleMemberAddMode = async (groupJid: string) => {
  // Get current metadata
  const metadata = await sock.groupMetadata(groupJid)

  // Toggle the setting
  const newMode = metadata.memberAddMode ? 'admin_add' : 'all_member_add'
  
  await sock.groupMemberAddMode(groupJid, newMode)

  console.log(`Member add mode set to: ${newMode}`)
  return newMode
}

Join Approval Mode

Control whether join requests require admin approval.

Function Signature

groupJoinApprovalMode(jid: string, mode: 'on' | 'off'): Promise<void>

Enable Join Approval

// Require admin approval for new members
await sock.groupJoinApprovalMode(jid, 'on')

Disable Join Approval

// Allow anyone with invite link to join directly
await sock.groupJoinApprovalMode(jid, 'off')
When join approval is enabled, users who click the invite link will need to request to join, and admins must approve them using groupRequestParticipantsUpdate.

Ephemeral Messages (Disappearing Messages)

Enable or disable disappearing messages for the group.

Function Signature

groupToggleEphemeral(jid: string, ephemeralExpiration: number): Promise<void>

Ephemeral Durations

DurationSecondsDescription
Remove0Disable ephemeral
24 hours86400Messages disappear in 1 day
7 days604800Messages disappear in 1 week
90 days7776000Messages disappear in 3 months

Enable Ephemeral Messages

// Enable 24-hour disappearing messages
await sock.groupToggleEphemeral(jid, 86400)

// Enable 7-day disappearing messages
await sock.groupToggleEphemeral(jid, 604800)

// Enable 90-day disappearing messages
await sock.groupToggleEphemeral(jid, 7776000)

Disable Ephemeral Messages

// Disable ephemeral messages
await sock.groupToggleEphemeral(jid, 0)

Helper Function

type EphemeralDuration = '24h' | '7d' | '90d' | 'off'

const setGroupEphemeral = async (
  groupJid: string,
  duration: EphemeralDuration
) => {
  const durations = {
    'off': 0,
    '24h': 86400,
    '7d': 604800,
    '90d': 7776000
  }

  const seconds = durations[duration]
  await sock.groupToggleEphemeral(groupJid, seconds)

  console.log(`Ephemeral messages set to: ${duration}`)
}

// Usage
await setGroupEphemeral(groupJid, '7d')

Leave Group

Leave a group you’re a member of.

Function Signature

groupLeave(id: string): Promise<void>

Leave a Group

// Will throw error if it fails
await sock.groupLeave(jid)
This action is irreversible. You’ll need to be re-invited to rejoin the group.

Safe Leave Function

const leaveGroup = async (groupJid: string) => {
  try {
    await sock.groupLeave(groupJid)
    console.log('Successfully left the group')
  } catch (error) {
    console.error('Failed to leave group:', error)
    throw error
  }
}

Complete Settings Configuration

Example of configuring multiple group settings:
1

Lock down the group

const lockdownGroup = async (groupJid: string) => {
  // Only admins can send messages
  await sock.groupSettingUpdate(groupJid, 'announcement')
  
  // Only admins can modify settings
  await sock.groupSettingUpdate(groupJid, 'locked')
  
  // Only admins can add members
  await sock.groupMemberAddMode(groupJid, 'admin_add')
  
  // Require approval to join
  await sock.groupJoinApprovalMode(groupJid, 'on')
  
  console.log('Group locked down successfully')
}
2

Open group settings

const openGroup = async (groupJid: string) => {
  // Everyone can send messages
  await sock.groupSettingUpdate(groupJid, 'not_announcement')
  
  // Everyone can modify settings
  await sock.groupSettingUpdate(groupJid, 'unlocked')
  
  // Everyone can add members
  await sock.groupMemberAddMode(groupJid, 'all_member_add')
  
  // No approval needed to join
  await sock.groupJoinApprovalMode(groupJid, 'off')
  
  console.log('Group opened successfully')
}
3

Configure privacy settings

const configureGroupPrivacy = async (groupJid: string) => {
  // Update name
  await sock.groupUpdateSubject(groupJid, 'Private Discussion Group')
  
  // Set description
  await sock.groupUpdateDescription(
    groupJid,
    'Confidential discussions only. Messages auto-delete after 7 days.'
  )
  
  // Enable 7-day ephemeral messages
  await sock.groupToggleEphemeral(groupJid, 604800)
  
  // Lock settings to admins only
  await sock.groupSettingUpdate(groupJid, 'locked')
  
  console.log('Privacy settings configured')
}

Best Practices

Check Admin Status: Always verify you have admin permissions before attempting to modify settings.
Sequential Updates: When making multiple setting changes, execute them sequentially to ensure each completes successfully.
Rate Limiting: Avoid making too many rapid setting changes. WhatsApp may rate-limit your requests.

Error Handling Pattern

const updateGroupSettings = async (
  groupJid: string,
  settings: {
    announcement?: boolean
    locked?: boolean
    ephemeral?: number
  }
) => {
  try {
    if (settings.announcement !== undefined) {
      await sock.groupSettingUpdate(
        groupJid,
        settings.announcement ? 'announcement' : 'not_announcement'
      )
    }

    if (settings.locked !== undefined) {
      await sock.groupSettingUpdate(
        groupJid,
        settings.locked ? 'locked' : 'unlocked'
      )
    }

    if (settings.ephemeral !== undefined) {
      await sock.groupToggleEphemeral(groupJid, settings.ephemeral)
    }

    console.log('Settings updated successfully')
  } catch (error) {
    console.error('Failed to update settings:', error)
    throw error
  }
}

// Usage
await updateGroupSettings(groupJid, {
  announcement: true,
  locked: true,
  ephemeral: 604800 // 7 days
})