HKUDS/nanobot · error · ValueError
Slack DM target for user
Error message
Slack DM target for user '{user_id}' could not be opened. What it means
Lookup failure in _open_dm_for_user: Slack's conversations.open call returned no channel/ID for the user, so a DM target could not be established even though the user ID was resolved. Usually a Slack API error, restricted DM, or token scope issue.
Solutions
- Check the bot token has the conversations:open (im:write) scope
- Verify the user allows DMs from workspace apps / is not deactivated
- Pass a concrete DM channel ID (starts with 'D') as the target to bypass DM opening
Defensive patterns
Strategy: try-catch
When it happens
Trigger: Thrown at nanobot/channels/slack/runtime.py:386 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of HKUDS/nanobot@42f37dc4c0 (2026-08-26).
Data as JSON: /api/errors/d1fb271781a0eb46.
Report an issue: GitHub.
Appendix: source
Thrown at nanobot/channels/slack/runtime.py:386
)
cursor = str(response_metadata.get("next_cursor") or "").strip()
if not cursor:
break
raise ValueError(
f"Slack user '{handle}' was not found. Use '@name' or a concrete DM/channel ID."
)
async def _open_dm_for_user(self, user_id: str) -> str:
web_api = self._require_web_api()
response = cast(
dict[str, Any],
await web_api.conversations_open(users=user_id),
)
channel = cast(dict[str, Any], response.get("channel") or {})
channel_id = str(channel.get("id") or "")
if not channel_id:
raise ValueError(f"Slack DM target for user '{user_id}' could not be opened.")
return channel_id
@staticmethod
def _normalize_target_name(value: str) -> str:
return value.strip().lstrip("#@").lower()
@classmethod
def _member_matches_handle(cls, member: dict[str, Any], normalized: str) -> bool:
profile = cast(dict[str, Any], member.get("profile") or {})
candidates = {
str(member.get("name") or ""),
str(profile.get("display_name") or ""),
str(profile.get("display_name_normalized") or ""),
str(profile.get("real_name") or ""),
str(profile.get("real_name_normalized") or ""),
}
return normalized in {cls._normalize_target_name(candidate) for candidate in candidates if candidate}
View on GitHub (pinned to 42f37dc4c0)