Skip to content

fix(discord): fetch and inject reply context for incoming messages#30085

Closed
alaamohanad169-ship-it wants to merge 1 commit into
NousResearch:mainfrom
alaamohanad169-ship-it:fix/discord-reply-context
Closed

fix(discord): fetch and inject reply context for incoming messages#30085
alaamohanad169-ship-it wants to merge 1 commit into
NousResearch:mainfrom
alaamohanad169-ship-it:fix/discord-reply-context

Conversation

@alaamohanad169-ship-it

Copy link
Copy Markdown
Contributor

Summary

When a user replies to a message in Discord, Hermes now fetches the referenced message content and prepends it to the incoming message text so the agent understands the context of the reply.

Problem

Issue #30049: When a user replies to a specific message in Discord, Hermes receives the new message text but has no awareness of which message was being replied to. This leads to confusing or incorrect responses because the agent can't see what the user is responding to.

The existing code only captured reply_to_text when Discord provided the resolved message object inline. This is unreliable — it's None for older messages, high-traffic servers, or cross-guild replies.

Fix

Two changes in _handle_message() in gateway/platforms/discord.py:

  1. Fetch the referenced message via API when message.reference.resolved is None:

    if reply_to_text is None and reply_to_id:
        ref_msg = await message.channel.fetch_message(int(reply_to_id))
        reply_to_text = getattr(ref_msg, "content", None)
  2. Prepends reply context to the message text so the agent sees it:

    [Replying to: "the original message text..."]
    the user's reply text
    

Caps at 200 characters to avoid flooding the context window.

Testing

  • Unit test: verify reply context is fetched when resolved is None
  • Unit test: verify reply context is prepended to event text
  • Integration test: verify agent receives full reply context in a Discord reply scenario

Fixes #30049

@alt-glitch alt-glitch added type/feature New feature or request P2 Medium — degraded but workaround exists comp/gateway Gateway runner, session dispatch, delivery platform/discord Discord bot adapter labels May 21, 2026
@alaamohanad169-ship-it

Copy link
Copy Markdown
Contributor Author

Superseded by a rebased version. Closing this PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp/gateway Gateway runner, session dispatch, delivery P2 Medium — degraded but workaround exists platform/discord Discord bot adapter type/feature New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat(gateway): resolve replied/quoted message context in Discord and WhatsApp

2 participants