Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions plugins/platforms/discord/adapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -7753,8 +7753,7 @@ async def _handle_message(
no_thread_channels = self._get_no_thread_channels()
skip_thread = bool(channel_keys & no_thread_channels) or is_free_channel
auto_thread = os.getenv("DISCORD_AUTO_THREAD", "true").lower() in {"true", "1", "yes"}
is_reply_message = getattr(message, "type", None) == discord.MessageType.reply
if auto_thread and not skip_thread and not is_voice_linked_channel and not is_reply_message:
if auto_thread and not skip_thread and not is_voice_linked_channel:
thread = await self._auto_create_thread(message)
if thread:
parent_channel_id = str(message.channel.id)
Expand Down
25 changes: 16 additions & 9 deletions tests/gateway/test_discord_free_response.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,28 +228,35 @@ async def test_discord_accepts_and_strips_bot_mentions_when_required(adapter, mo


@pytest.mark.asyncio
async def test_discord_reply_message_skips_auto_thread(adapter, monkeypatch):
"""Quote-replies should stay in-channel instead of trying to create a thread."""
async def test_discord_reply_message_auto_threads_when_channel_is_eligible(adapter, monkeypatch):
"""Quote-replies should use the same auto-thread routing as new messages."""
monkeypatch.delenv("DISCORD_AUTO_THREAD", raising=False)
monkeypatch.setenv("DISCORD_REQUIRE_MENTION", "true")
monkeypatch.setenv("DISCORD_FREE_RESPONSE_CHANNELS", "123")
monkeypatch.setenv("DISCORD_REQUIRE_MENTION", "false")
monkeypatch.delenv("DISCORD_FREE_RESPONSE_CHANNELS", raising=False)

adapter._auto_create_thread = AsyncMock()
parent = FakeTextChannel(channel_id=123)
thread = FakeThread(channel_id=999, parent=parent)
adapter._auto_create_thread = AsyncMock(return_value=thread)

message = make_message(
channel=FakeTextChannel(channel_id=123),
channel=parent,
content="reply without mention",
msg_type=discord_platform.discord.MessageType.reply,
)
message.reference = SimpleNamespace(
message_id=456,
resolved=SimpleNamespace(id=456, content="the message being replied to"),
)

await adapter._handle_message(message)

adapter._auto_create_thread.assert_not_awaited()
adapter._auto_create_thread.assert_awaited_once_with(message)
adapter.handle_message.assert_awaited_once()
event = adapter.handle_message.await_args.args[0]
assert event.text == "reply without mention"
assert event.source.chat_id == "123"
assert event.source.chat_type == "group"
assert event.source.chat_id == "999"
assert event.source.chat_type == "thread"
assert event.source.thread_id == "999"


@pytest.mark.asyncio
Expand Down