Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@nonggialiang
Copy link
Contributor

Summary

Fixes #2627

When sending Discord messages via cron jobs or the message tool, usernames like `john.doe` were incorrectly treated as channel names, causing silent delivery failures.

Problem

The Discord outbound adapter had no `resolveTarget` hook. The `parseDiscordTarget()` function fell back to treating unrecognized strings as channel names:
```typescript
return buildMessagingTarget("channel", trimmed, trimmed);
```

So `john.doe` was passed as a channel name lookup, which fails because no channel named `john.doe` exists.

Solution

This fix adds a `resolveDiscordTarget()` function that:

  • Queries Discord directory to resolve usernames to user IDs using `listDiscordDirectoryPeersLive()`
  • Falls back to standard parsing for known formats (user:, channel:, @mentions, numeric IDs)
  • Enables sending DMs by username without requiring explicit `user:ID` format

Changes

  • src/discord/targets.ts: Added `resolveDiscordTarget()` function with directory lookup
  • src/discord/send.shared.ts: Added `parseAndResolveRecipient()` wrapper function
  • src/discord/send.outbound.ts: Updated `sendMessageDiscord()`, `sendStickerDiscord()`, and `sendPollDiscord()` to use username resolution

Testing

After this fix, cron jobs can target usernames:
```json
{
"to": "john.doe",
"channel": "discord"
}
```

The username will be resolved to a Discord user ID, and the message will be delivered as a DM.


Note: This is a first step. For username resolution to work, Discord directory integration must be configured and bot must have access to guild member lists.

@moltbot-barnacle moltbot-barnacle bot added the channel: discord Channel integration: discord label Jan 27, 2026
@thewilloftheshadow thewilloftheshadow self-assigned this Jan 28, 2026
nonggialiang and others added 6 commits January 27, 2026 21:04
When sending Discord messages via cron jobs or the message tool,
usernames like "john.doe" were incorrectly treated as channel names,
causing silent delivery failures.

This fix adds a resolveDiscordTarget() function that:
- Queries Discord directory to resolve usernames to user IDs
- Falls back to standard parsing for known formats
- Enables sending DMs by username without requiring explicit user:ID format

Changes:
- Added resolveDiscordTarget() in targets.ts with directory lookup
- Added parseAndResolveRecipient() in send.shared.ts
- Updated all outbound send functions to use username resolution

Fixes moltbot#2627
@thewilloftheshadow thewilloftheshadow force-pushed the fix/discord-username-resolution branch from 834396c to f2f85bb Compare January 28, 2026 03:05
@thewilloftheshadow thewilloftheshadow merged commit 7bfe6ab into openclaw:main Jan 28, 2026
11 of 23 checks passed
@thewilloftheshadow
Copy link
Member

Landed via temp rebase onto main.

  • Related tests: pnpm vitest run --config vitest.unit.config.ts src/discord/targets.test.ts
  • Land commit: f2f85bb
  • Merge commit: 7bfe6ab

Thanks @nonggialiang!

bonald pushed a commit to bonald/moltbot that referenced this pull request Jan 28, 2026
jsholmes added a commit to jsholmes/clawdbot that referenced this pull request Jan 28, 2026
The upstream PR openclaw#2649 merged with incorrect import paths:
- DirectoryConfigParams and ChannelDirectoryEntry were imported from
  '../channels/targets.js' but actually exist in the plugins directory.

Fixes:
- Import DirectoryConfigParams from '../channels/plugins/directory-config.js'
- Remove unused ChannelDirectoryEntry import
- Fix parseDiscordTarget() calls in resolveDiscordTarget() to not pass
  incompatible DirectoryConfigParams to MessagingTargetParseOptions

This fixes the TypeScript build error introduced by upstream commit 7958ead.
danbao pushed a commit to danbao/openclaw that referenced this pull request Jan 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

channel: discord Channel integration: discord

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Discord outbound adapter doesn't resolve usernames to user IDs - messages fail silently

2 participants