Skip to content

Fix/discord integration#289

Draft
makiroll1125 wants to merge 2 commits into
V1.3.2from
fix/discord-integration
Draft

Fix/discord integration#289
makiroll1125 wants to merge 2 commits into
V1.3.2from
fix/discord-integration

Conversation

@makiroll1125
Copy link
Copy Markdown
Collaborator

@makiroll1125 makiroll1125 commented May 28, 2026

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_reference and referenced_message fields from the Discord gateway event were silently discarded, leaving the agent unable to reference, quote, or edit the original message.

  • Channel vs DM misdetectedchannel_name was derived from whether guild_id was 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:

  • Added 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.
  • In _handle_message_create: reads message_reference.message_id from the event, uses the referenced_message object when present (Discord includes it most of the time with MESSAGE_CONTENT intent).
  • Passes reply_to_id, reply_to_text, and reply_to_author into the raw dict for later use.
  • Appends a [REPLYING TO message_id=... (from <author>): "..."] line to event_content for both self-message and third-party message paths, giving the agent full context on what was replied to.

Channel/DM fix:

  • Replaced guild-ID-based DM inference with channel_type-based detection (channel_type in (1, 3) → DM), matching the Discord specifications.
  • Stores channel_type and is_dm in raw alongside the existing fields.
  • The action-selection platform hint now reads channel_name from 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_CREATE event always includes message_reference (and usually referenced_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, using guild_id presence to detect DMs was fragile as Discord's channel_type field is the proper signal for this.

How to test

  • Send a message in a Discord guild channel → agent correctly identifies the channel name and replies there
  • Reply to a bot message in a channel → agent's event content includes the [REPLYING TO ...] line with the correct message_id and original text
  • Non-reply message → no [REPLYING TO ...] line appears (reply fields are None)

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?"

image

@makiroll1125 makiroll1125 self-assigned this May 28, 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