Portal Community

channel/leave

Removes the bot from a Slack channel. After leaving, the bot can no longer post to or read history from the channel unless it re-joins or is re-invited. This is a bot-self-action — use channel/kick to remove other users. Requires channels:manage scope.

When to Use

Configuration

Connection

FieldTypeRequiredDescription
botTokenstringRequiredBot Token starting with xoxb-. Requires channels:manage scope.

Operation Fields

FieldTypeRequiredDescription
channelIdstringRequiredThe channel ID to leave. Can be public (C...) or private (G...).
Irreversible Access Loss: After leaving a private channel, the bot cannot re-join on its own. A workspace admin or existing channel member must re-invite it. Confirm the bot is no longer needed before leaving a private channel.

Sample Configuration

{
  "operation": "channel/leave",
  "connection": {
    "botToken": "{{credentials.slackBotToken}}"
  },
  "fields": {
    "channelId": "{{$json.channelId}}"
  }
}

Validation Errors

Error CodeCauseResolution
channel_not_foundThe channel ID is invalid or the bot is not a member of it.Verify the channel ID. If the bot is not in the channel, the leave operation is a no-op.
missing_scopeBot token lacks channels:manage scope.Re-authorize the Slack app with the channels:manage scope.

Output

Success Port

FieldTypeDescription
channelIdstringThe channel the bot left.
statusstringsuccess or error.
errorCodestringSlack error code when status is error.
payloadobjectFull raw Slack API response.

Error Port

On failure with Continue on Error enabled, routes to the error port with status: "error" and populated errorCode.

Sample Output

{
  "channelId": "C08AB3XYZ12",
  "status": "success",
  "errorCode": "",
  "payload": {
    "ok": true
  }
}

Expression Reference

ExpressionResult
{{$node["channel-leave"].json.channelId}}The channel ID that was left — use for audit log entries.
{{$node["channel-leave"].json.status === "success"}}Boolean confirmation — gate downstream cleanup steps.

Node Policies & GuardRails

Policy AreaRecommendation
Scope requirementsRequires channels:manage scope.
Rate limitingTier 2 (20+ req/min). For bulk leave operations, add delays between calls.
No hard-coded IDsAlways source channelId dynamically from upstream data. Never hard-code channel IDs.
Private channel warningLeaving a private channel is difficult to reverse. Always confirm via an approval step or IF node before leaving private channels in production.
Archive instead of leaveFor channels the bot owns or manages, consider channel/archive rather than simply leaving — archived channels preserve history and prevent reuse of the name.
Audit trailLog each leave action with channelId, channel name, and timestamp to your audit system.

Examples

Example 1 — Post-Project Cleanup

When a project is marked complete in the project tracker, the bot posts a final status update and then leaves the channel.

// Node 1: message/send — final status update
{
  "channelId": "{{$json.channelId}}",
  "text": "Project {{$json.projectName}} is now complete. This channel will be archived. Thanks, team!"
}

// Node 2: channel/leave
{ "channelId": "{{$json.channelId}}" }

// Node 3: channel/archive
{ "channelId": "{{$json.channelId}}" }

Example 2 — Post-Event Channel Cleanup

Scheduled workflow that leaves all event channels older than 30 days based on createdTimestamp.

// Node 1: channel/getMany — get all channels
// Code node: filter channels matching "event-" prefix older than 30 days
const thirtyDaysAgo = Date.now() / 1000 - (30 * 86400);
const oldEventChannels = $node["channel-getmany"].json.channels
  .filter(c => c.channelName.startsWith('event-') && c.createdTimestamp < thirtyDaysAgo);
// Loop: channel/leave for each

Example 3 — Bot Footprint Audit

Monthly scheduled audit that leaves any public channels where the bot has had no activity in 60 days.

// For each channel the bot is in:
// 1. channel/getHistory (last 60 days, limit 1)
// 2. IF: messageCount === 0 AND no bot messages
//    True → channel/leave
//    False → skip (bot is active here)