#18512: feat(discord): Add resolveUser action for username-based user lookup
agents
stale
size: S
Cluster:
Signal and Discord Fixes
## Summary
Adds a new `resolveUser` action to the Discord integration that allows searching for Discord users by username across servers where the bot is a member.
## Problem
Previously, Discord user lookup was only possible by user ID. Users had to manually copy User IDs from Discord to reference other users through the bot, which was cumbersome and not user-friendly.
## Solution
Leverages the existing `resolveDiscordUserAllowlist` function which uses Discord's `/guilds/{guild.id}/members/search` API to search for users by username, nickname, or global name across all accessible guilds.
## Usage
```json
{
action: resolveUser,
query: username // or "guild/username", "@username", or "user:ID"
}
```
**Examples:**
- `query: "ahsan"` - searches all guilds for username
- `query: "MyServer/ahsan"` - searches specific guild
- `query: "@ahsan"` - searches with @ prefix
- `query: "user:123456789"` - resolves by ID directly
## Response
```json
{
"ok": true,
"results": [
{
"input": "ahsan",
"resolved": true,
"id": "1473015907243790509",
"name": "Ahsan",
"guildId": "1472551850682089534",
"guildName": "AhsanDev",
"note": "multiple matches; chose best"
}
]
}
```
## Changes
- `src/agents/tools/discord-actions-guild.ts` - Added resolveUser action handler
- `src/agents/tools/discord-actions.ts` - Registered resolveUser in guildActions
- `src/channels/plugins/actions/discord/handle-action.ts` - Exposed resolveUser through message tool
- `src/channels/plugins/message-action-names.ts` - Added to action names list
- `src/infra/outbound/message-action-spec.ts` - Added target mode specification
- `test-resolve-user.ts` - Added test script for verification
## Testing
Tested locally with:
```bash
npx tsx test-resolve-user.ts ahsan
```
Successfully resolves users across shared Discord servers.
## Limitations
- Users must be in at least one Discord server where the bot is a member
- Bot requires "Server Intent: Members" permission
- Cannot search Discord's global user database (Discord privacy feature)
- Users not in shared servers cannot be found by username
## Notes
This feature works within Discord's privacy model - it can only search members of servers the bot has access to, which is the only supported method for username-based user lookup.
<!-- greptile_comment -->
<h3>Greptile Summary</h3>
Adds a `resolveUser` action to the Discord integration, allowing username-based user lookup across guilds where the bot is a member. The implementation leverages the existing `resolveDiscordUserAllowlist` function and wires it through the guild action handler, message action handler, and action name/spec registries.
- The action name `resolveUser` uses camelCase in `message-action-names.ts`, which is inconsistent with the kebab-case convention used by all other Discord-specific actions (`member-info`, `role-info`, `channel-create`, etc.). It should be `resolve-user` with a mapping in `handle-action.guild-admin.ts`.
- A manual test script (`test-resolve-user.ts`) is committed at the project root, which is non-standard — all other test files live inside `src/`, `test/`, `scripts/`, or `extensions/`.
- The `resolveUser` action is gated behind the `memberInfo` permission flag without a dedicated config key, meaning operators cannot independently control this capability.
<h3>Confidence Score: 3/5</h3>
- Functionally correct but has naming convention inconsistencies and a stray test file that should be addressed before merging.
- The core logic is sound — it correctly uses the existing `resolveDiscordUserAllowlist` function and properly validates the token. However, the naming convention inconsistency (camelCase vs kebab-case) breaks the established pattern for Discord actions and the handler placement diverges from the existing guild-admin pattern. The committed root-level test script is a development artifact.
- `src/channels/plugins/message-action-names.ts` (naming convention), `test-resolve-user.ts` (should not be at project root), `src/channels/plugins/actions/discord/handle-action.ts` (handler placement diverges from pattern)
<sub>Last reviewed commit: 68b61ec</sub>
<!-- greptile_other_comments_section -->
<sub>(2/5) Greptile learns from your feedback when you react with thumbs up/down!</sub>
<!-- /greptile_comment -->
Most Similar PRs
#20697: feat(discord): auto-resolve user mentions in message content
by tdjackey · 2026-02-19
77.5%
#12204: fix(discord): resolve numeric guildId/channelId pairs in channel al...
by mcaxtr · 2026-02-09
75.5%
#19615: fix(discord): include default account when sub-accounts are configured
by prue-starfield · 2026-02-18
73.3%
#16720: fix: fall back to guild_id when guild object is missing in resolveD...
by xqliu · 2026-02-15
72.5%
#23689: feat(discord): add ignoreOtherMentions config option
by Q00 · 2026-02-22
72.3%
#11491: feat(slack): allow agents to resolve channel IDs to names and list ...
by Lukavyi · 2026-02-07
72.0%
#14224: feat(telegram): add member-info action to get chat administrators
by ivan-andreyev · 2026-02-11
71.6%
#22557: fix(discord): coerce exec approval approver IDs to string to preven...
by zwffff · 2026-02-21
71.1%
#10712: feat(discord): add compact mode for message reads
by skoteskote · 2026-02-06
71.1%
#23158: discord: harden preflight/reply path against slow lookup latency
by danielstarman · 2026-02-22
71.0%