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
- Project completion offboarding: When a project is marked complete and the project channel is being wound down, the bot leaves to keep its active channel list clean.
- Temporary event channel cleanup: After a scheduled event (conference, hackathon, sprint) ends, leave the temporary event coordination channels that are no longer active.
- Bot footprint reduction: Periodically audit and leave channels where the bot has been dormant and has no active workflows — reduces noise in channel member lists.
Configuration
Connection
| Field | Type | Required | Description |
|---|---|---|---|
botToken | string | Required | Bot Token starting with xoxb-. Requires channels:manage scope. |
Operation Fields
| Field | Type | Required | Description |
|---|---|---|---|
channelId | string | Required | The 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 Code | Cause | Resolution |
|---|---|---|
channel_not_found | The 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_scope | Bot token lacks channels:manage scope. | Re-authorize the Slack app with the channels:manage scope. |
Output
Success Port
| Field | Type | Description |
|---|---|---|
channelId | string | The channel the bot left. |
status | string | success or error. |
errorCode | string | Slack error code when status is error. |
payload | object | Full 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
| Expression | Result |
|---|---|
{{$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 Area | Recommendation |
|---|---|
| Scope requirements | Requires channels:manage scope. |
| Rate limiting | Tier 2 (20+ req/min). For bulk leave operations, add delays between calls. |
| No hard-coded IDs | Always source channelId dynamically from upstream data. Never hard-code channel IDs. |
| Private channel warning | Leaving 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 leave | For channels the bot owns or manages, consider channel/archive rather than simply leaving — archived channels preserve history and prevent reuse of the name. |
| Audit trail | Log 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)