Skip to content

fix(discord): auto-join threads under allowed_channels to enable bot-to-bot @mention delivery #1107

@chaodu-agent

Description

@chaodu-agent

Summary

Bot-to-bot @mention in threads is broken because Discord Gateway does not deliver MESSAGE_CREATE to bots that are not thread members. This makes the trusted_bot_ids bypass added in #967 ineffective — the application-layer logic never fires.

Related: #974 (bug report), #967 (application-layer fix), #950 (involvement gate docs)

Root Cause

Discord treats thread event delivery differently for bots vs humans:

  • Human @mentions a bot in a thread → Discord auto-adds the bot to thread member list → bot receives MESSAGE_CREATE
  • Bot @mentions another bot in a thread → Discord does NOT auto-add → target bot never receives the event

This is confirmed by Discord official docs (Threads - Thread Membership):

Each thread tracks explicit membership.

And validated by live testing: human mention works, bot mention in the same thread does not.

Proposed Fix

Implement a THREAD_CREATE / THREAD_UPDATE Gateway event handler that auto-joins threads whose parent channel is in allowed_channels (or allow_all_channels = true).

When the bot receives a THREAD_CREATE event for a new thread under a monitored channel, call:

PUT /channels/{thread_id}/thread-members/@me

This ensures the bot is always a thread member for relevant threads, so:

  1. It receives all MESSAGE_CREATE events in those threads
  2. The existing feat(discord): trusted bot @mention bypasses involvement gate #967 trusted_bot_ids bypass logic can actually fire
  3. Bot-to-bot @mention collaboration works as documented

Alternatives Considered

  1. Reactive approach: When Bot A sends a message mentioning Bot B, Bot A calls PUT /channels/{thread_id}/thread-members/{bot_b_id} to add Bot B. Downside: requires Bot A to have MANAGE_THREADS permission and know Bot B's ID.

  2. Proactive auto-join (proposed): Each bot joins threads under its own allowed_channels on THREAD_CREATE. Simpler, no cross-bot coordination needed, each bot is self-sufficient.

Impact

Without this fix, the multi-agent collaboration feature (trusted_bot_ids + allow_bot_messages=mentions) cannot work for bot-initiated conversations in threads — only human-initiated ones work.

Environment

  • Version: 0.8.5+
  • Platform: Discord
  • Config: allow_bot_messages = "mentions", trusted_bot_ids set

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingdiscordfeaturep2Medium — planned work

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions