#15759: discord: fix sender undefined type errors in message handler
channel: discord
stale
size: XS
Cluster:
Signal and Discord Fixes
## Summary
- fix TS18048 (`sender` possibly undefined) in Discord message processing
- derive `resolvedSender` once via fallback identity when `sender` is absent
- use `resolvedSender` for label/name/tag/id and owner allow-list context
## Scope
- only `/src/discord/monitor/message-handler.process.ts`
- no changes to preflight types/params
## Validation
- `pnpm -s lint src/discord/monitor/message-handler.process.ts`
- `pnpm -s exec tsc --noEmit`
<!-- greptile_comment -->
<h2>Greptile Overview</h2>
<h3>Greptile Summary</h3>
This change updates `processDiscordMessage` to stop directly dereferencing `ctx.sender` and instead derive a `resolvedSender` (using `ctx.sender` when present, otherwise a fallback from `resolveDiscordSenderIdentity`). The resolved identity is then used consistently for sender label/name/tag/id and for allow-list context, eliminating TS18048 “possibly undefined” errors while keeping the rest of the message processing and routing flow unchanged.
<h3>Confidence Score: 5/5</h3>
- This PR is safe to merge with minimal risk.
- The change is localized to sender identity dereferencing, uses an existing identity resolver for fallback, and does not alter external interfaces or control flow; no functional regressions were found after tracing preflight sender construction and the identity resolver implementation.
- No files require special attention
<sub>Last reviewed commit: e8e4dca</sub>
<!-- greptile_other_comments_section -->
<sub>(3/5) Reply to the agent's comments like "Can you suggest a fix for this @greptileai?" or ask follow-up questions!</sub>
<!-- /greptile_comment -->
Most Similar PRs
#21804: fix: improve type safety and use project runtime logging
by hobostay · 2026-02-20
75.1%
#23158: discord: harden preflight/reply path against slow lookup latency
by danielstarman · 2026-02-22
74.5%
#17254: fix(discord): intercept text-based slash commands instead of forwar...
by robbyczgw-cla · 2026-02-15
74.4%
#17648: fix: Discord guild channel detection using rawMessage.guild_id
by MisterGuy420 · 2026-02-16
74.2%
#21463: fix(discord): prevent WebSocket death spiral + fix numeric channel ID…
by akropp · 2026-02-20
74.1%
#9734: fix(telegram): correct sender identification for channel messages (...
by divol89 · 2026-02-05
73.8%
#20913: fix: intercept Discord embed images to enforce mediaMaxMb
by MumuTW · 2026-02-19
73.7%
#12204: fix(discord): resolve numeric guildId/channelId pairs in channel al...
by mcaxtr · 2026-02-09
73.6%
#16801: fix: Register Discord listeners before gateway connects
by MisterGuy420 · 2026-02-15
73.6%
#15900: fix(discord): filter bot's own messages early to prevent self-DoS
by Shuai-DaiDai · 2026-02-14
73.5%