Skip to content

fix(discord): force-fetch channels to prevent stale cache "not allowlisted" errors#1373

Closed
matt-landers wants to merge 1 commit intoanthropics:mainfrom
matt-landers:main
Closed

fix(discord): force-fetch channels to prevent stale cache "not allowlisted" errors#1373
matt-landers wants to merge 1 commit intoanthropics:mainfrom
matt-landers:main

Conversation

@matt-landers
Copy link
Copy Markdown

Summary

Fixes intermittent channel X is not allowlisted errors caused by stale Discord.js channel cache. Relates to #983.

After idle time or permission approval flows, client.channels.fetch(id) can return partial/stale channel objects where properties like recipientId are null or incorrect, causing fetchAllowedChannel to reject valid channels.

Changes

  • fetchTextChannel: Handle partial channels by calling ch.fetch() when ch.partial is true
  • fetchAllowedChannel: Use client.channels.fetch(id, { force: true }) to bypass the Discord.js cache entirely, ensuring a fresh channel object on every outbound gate check

How to reproduce

  1. Configure a DM channel with a user in allowFrom
  2. Send a message to trigger the bot
  3. Either wait a few minutes (cache goes stale) or approve a permission request via Discord buttons
  4. Bot attempts to reply — fails with "not allowlisted"
  5. Send another message — reply works again (cache refreshed by gateway event)

Testing

Verified fix on a live Discord group channel that was consistently failing after idle and after permission approvals. After applying { force: true }, replies work reliably regardless of cache state.

…sted errors

Discord.js channel cache can return partial objects after idle, causing fetchAllowedChannel to fail even when the channel is correctly configured. Using { force: true } bypasses the cache, and handling partial channels ensures properties like recipientId and type are always populated.

Fixes anthropics#983
@github-actions
Copy link
Copy Markdown

Thanks for your interest! This repo only accepts contributions from Anthropic team members. If you'd like to submit a plugin to the marketplace, please submit your plugin here.

@github-actions github-actions bot closed this Apr 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant