Skip to content

Discord: addReaction/removeReaction/deleteMessage use wrong channel ID for thread messages #130

@arvinxx

Description

@arvinxx

Bug Description

addReaction, removeReaction, and deleteMessage in the Discord adapter use channelId (parent channel) instead of the thread channel ID when operating on messages inside threads. This causes 404 "Unknown Message" errors from the Discord API.

Most other methods (editMessage, postMessage, startTyping, fetchMessages) correctly resolve the thread channel using the pattern const targetChannelId = discordThreadId || channelId, but these three methods were missed.

Steps to Reproduce

  1. Bot receives a message in a Discord thread
  2. Call adapter.addReaction(threadId, message.id, emoji)
  3. Discord API returns 404 "Unknown Message"
Discord API error {
  path: '/channels/1233998293818671126/messages/1476970862816268483/reactions/%F0%9F%91%80/@me',
  method: 'PUT',
  status: 404,
  error: '{"message": "Unknown Message", "code": 10008}'
}

The channel 1233998293818671126 is the parent channel, but the message lives in thread 1476968053597274124.

Expected Behavior

addReaction/removeReaction/deleteMessage should use the thread ID (4th segment of the thread ID) as the channel for API calls, matching the behavior of editMessage, postMessage, startTyping, and fetchMessages.

Actual Behavior

These methods only extract channelId from decodeThreadId() and ignore the threadId component:

// Current (buggy) — addReaction:
async addReaction(threadId, messageId, emoji) {
  const { channelId } = this.decodeThreadId(threadId);  // ignores threadId
  await this.discordFetch(
    `/channels/${channelId}/messages/${messageId}/reactions/${emojiEncoded}/@me`,
    "PUT"
  );
}

Fix

Apply the same pattern used by editMessage, startTyping, fetchMessages:

async addReaction(threadId, messageId, emoji) {
  const { channelId, threadId: discordThreadId } = this.decodeThreadId(threadId);
  const targetChannelId = discordThreadId || channelId;
  const emojiEncoded = this.encodeEmoji(emoji);
  await this.discordFetch(
    `/channels/${targetChannelId}/messages/${messageId}/reactions/${emojiEncoded}/@me`,
    "PUT"
  );
}

Same fix for removeReaction and deleteMessage.

Affected Methods

Method Uses thread ID? Status
postMessage ✅ Yes Correct
editMessage ✅ Yes Correct
startTyping ✅ Yes Correct
fetchMessages ✅ Yes Correct
addReaction ❌ No Bug
removeReaction ❌ No Bug
deleteMessage ❌ No Bug

Related

#127 — similar thread context issue but for incoming reaction events

Chat SDK Version

4.15.0

Platform Adapter

Discord

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions