binary-husky/gpt_academic · error · Exception

Channel not found.

Error message

Channel not found.

What it means

Thrown by the SlackClient wrapper used by the Slack-relay Claude bridge: chat() refuses to post a message while self.CHANNEL_ID is None. CHANNEL_ID is only populated by open_channel(), which calls conversations_open with SLACK_CLAUDE_BOT_ID; if that step was skipped or failed silently, every chat() call aborts.

Source

Thrown at request_llms/bridge_stackclaude.py:49

        方法:
        - open_channel():异步方法。通过调用conversations_open方法打开一个频道,并将返回的频道ID保存在属性CHANNEL_ID中。
        - chat(text: str):异步方法。向已打开的频道发送一条文本消息。
        - get_slack_messages():异步方法。获取已打开频道的最新消息并返回消息列表,目前不支持历史消息查询。
        - get_reply():异步方法。循环监听已打开频道的消息,如果收到"Typing…_"结尾的消息说明Claude还在继续输出,否则结束循环。

        """

        CHANNEL_ID = None

        async def open_channel(self):
            response = await self.conversations_open(
                users=get_conf("SLACK_CLAUDE_BOT_ID")
            )
            self.CHANNEL_ID = response["channel"]["id"]

        async def chat(self, text):
            if not self.CHANNEL_ID:
                raise Exception("Channel not found.")

            resp = await self.chat_postMessage(channel=self.CHANNEL_ID, text=text)
            self.LAST_TS = resp["ts"]

        async def get_slack_messages(self):
            try:
                # TODO:暂时不支持历史消息,因为在同一个频道里存在多人使用时历史消息渗透问题
                resp = await self.conversations_history(
                    channel=self.CHANNEL_ID, oldest=self.LAST_TS, limit=1
                )
                msg = [
                    msg
                    for msg in resp["messages"]
                    if msg.get("user") == get_conf("SLACK_CLAUDE_BOT_ID")
                ]
                return msg
            except (SlackApiError, KeyError) as e:
                raise RuntimeError(f"获取Slack消息失败。")

View on GitHub (pinned to d6bde0fa54)

Solutions

  1. Ensure SLACK_CLAUDE_BOT_ID and SLACK_CLAUDE_USER_TOKEN are set correctly in config_private.py
  2. Always await open_channel() (and verify CHANNEL_ID is set) before the first chat() call
  3. Check the token scopes: it needs im:write (or conversations:write) plus chat:write to open and post to the DM channel
  4. Inspect the conversations_open response in Slack's API tester with the same token to confirm channel.id is returned

Example fix

# before
client = SlackClient(token=TOKEN, proxy=p)
await client.chat('hello')  # CHANNEL_ID is None -> raises

# after
client = SlackClient(token=TOKEN, proxy=p)
await client.open_channel()
assert client.CHANNEL_ID, 'failed to open Slack DM channel'
await client.chat('hello')
Defensive patterns

Strategy: validation

Validate before calling

client = SlackClient(token=TOKEN, proxy=proxies)
await client.open_channel()
if not client.CHANNEL_ID:
    raise ConfigurationError('conversations_open failed - check SLACK_CLAUDE_BOT_ID and token scopes')

Try / catch

try:
    await client.chat(text)
except Exception as e:
    if 'Channel not found' in str(e):
        await client.open_channel()
        await client.chat(text)
    else:
        raise

Prevention

When it happens

Trigger: Calling chat(text) before open_channel() completed, or after conversations_open() returned a payload without channel.id (KeyError swallowed upstream), or when SLACK_CLAUDE_BOT_ID is misconfigured so the DM channel cannot be opened. Defined in request_llms/bridge_stackclaude.py:49.

Common situations: SLACK_CLAUDE_BOT_ID not set in config; Slack user token (SLACK_CLAUDE_USER_TOKEN) lacks the im:write / conversations scopes so conversations_open fails; the bot was removed or the workspace changed; async_run() ordering bug where chat runs before open_channel's await finished.

Related errors


AI-assisted analysis of binary-husky/gpt_academic@d6bde0fa54 (2026-08-14). Data as JSON: /api/errors/074cb6af4398f69b. Report an issue: GitHub.