← Back to PRs

#13637: fix(discord): add proxy support for media attachment downloads

by ayanesakura open 2026-02-10 19:49 View on GitHub →
docs channel: discord channel: telegram stale
## Summary Fixes #2503 Discord's `resolveMediaList` calls `fetchRemoteMedia` without a `fetchImpl`, causing it to fall back to `globalThis.fetch`. On Node.js 22+ the native fetch is backed by undici and bypasses `http.request`, so `global-agent` cannot intercept it — making media downloads from `cdn.discordapp.com` fail in proxy-required environments (e.g. China mainland). This PR adds a `channels.discord.proxy` config field (mirroring Telegram's existing pattern) and threads a proxy-aware fetch through the message handler pipeline into `resolveMediaList` → `fetchRemoteMedia`. ## Problem ``` config.proxy → ??? → resolveMediaList() → fetchRemoteMedia({ url }) ↓ fetchImpl is undefined ↓ falls back to globalThis.fetch ↓ Node 22 undici fetch (no global-agent) ↓ cdn.discordapp.com unreachable ❌ ``` Telegram already handles this correctly via `makeProxyFetch` → `fetchRemoteMedia({ fetchImpl })`. ## Changes - **Config**: add `proxy?: string` to `DiscordAccountConfig` type + zod schema - **Infra**: move `makeProxyFetch` from `src/telegram/proxy.ts` to `src/infra/net/proxy.ts` as shared infrastructure (Telegram re-exports for backward compat) - **Provider**: create proxy-aware fetch when `channels.discord.proxy` is set - **Pipeline**: thread `proxyFetch` through `createDiscordMessageHandler` → `preflightDiscordMessage` → `processDiscordMessage` → `resolveMediaList` → `fetchRemoteMedia` - **Docs**: update English + Chinese Discord docs with proxy config field - **Changelog**: add entry under Fixes ## Data flow (after fix) ``` channels.discord.proxy: "http://host:port" ↓ makeProxyFetch(proxyUrl) → undici ProxyAgent ↓ createDiscordMessageHandler({ proxyFetch }) ↓ preflightDiscordMessage(params) → ctx.proxyFetch ↓ processDiscordMessage(ctx) ↓ resolveMediaList(message, maxBytes, proxyFetch) ↓ fetchRemoteMedia({ url, fetchImpl: proxyFetch }) ✅ ``` ## Test plan - [x] `tsc --noEmit` passes (zero errors) - [x] `oxlint` passes (zero warnings/errors) - [x] All 187 existing Discord tests pass (zero regressions) - [x] Telegram `proxy.test.ts` passes (re-export backward compat) - [x] Added 2 unit tests: `resolveMediaList` correctly passes/omits `fetchImpl` - [x] Added 2 integration tests: `processDiscordMessage` threads `proxyFetch` from context into `fetchRemoteMedia` for attachment downloads ## Config example ```json5 { channels: { discord: { token: "YOUR_BOT_TOKEN", proxy: "http://your-proxy:port", }, }, } ``` 🤖 Generated with [Claude Code](https://claude.com/claude-code)

Most Similar PRs