Fix/discord integration#289
Draft
makiroll1125 wants to merge 2 commits into
Draft
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Two bugs in the Discord integration that caused the agent to misread or lose context from incoming messages:
Reply context missing — When a user replied to a bot message in Discord, the agent had no awareness of what was being replied to. The
message_referenceandreferenced_messagefields from the Discord gateway event were silently discarded, leaving the agent unable to reference, quote, or edit the original message.Channel vs DM misdetected —
channel_namewas derived from whetherguild_idwas present, which is unreliable for certain channel types. This caused DMs to occasionally be labelled as channels and vice versa, feeding the wrong context into the action-selection prompt (e.g., instructing the agent to reply in a channel when it should reply via DM).What
Reply fix:
get_message(channel_id, message_id)endpoint to fetch a referenced message by ID. Even though get_messages() could technically work, it is less efficient for a singular message._handle_message_create: readsmessage_reference.message_idfrom the event, uses thereferenced_messageobject when present (Discord includes it most of the time withMESSAGE_CONTENTintent).reply_to_id,reply_to_text, andreply_to_authorinto the raw dict for later use.[REPLYING TO message_id=... (from <author>): "..."]line toevent_contentfor both self-message and third-party message paths, giving the agent full context on what was replied to.Channel/DM fix:
channel_type-based detection (channel_type in (1, 3)→ DM), matching the Discord specifications.channel_typeandis_dminrawalongside the existing fields.channel_namefrom the payload ("DM"vs"#<id>") and builds a context-aware reply instruction:"from Discord via DM (reply on Discord to this DM, NOT send_message)"vs"from Discord in channel #... (reply on Discord in the same channel, NOT send_message)".Why
The Discord gateway
MESSAGE_CREATEevent always includesmessage_reference(and usuallyreferenced_message) when a message is a reply. Ignoring these fields meant the agent treated every incoming message as a standalone message, making it impossible to track conversation threads or act on the original message. Similarly, usingguild_idpresence to detect DMs was fragile as Discord'schannel_typefield is the proper signal for this.How to test
[REPLYING TO ...]line with the correctmessage_idand original text[REPLYING TO ...]line appears (reply fields areNone)Screenshots / Logs
[REPLYING TO message_id=1509407731377766453 (from Lobster)]: "Sure! Which message would you like me to edit, and what should I change it to say?"