Skip to content

fix(discord): fix slash command detection when auto-create-thread is on#6293

Closed
dsocolobsky wants to merge 3 commits into
NousResearch:mainfrom
dsocolobsky:discord-fix-slash-commands-in-channel
Closed

fix(discord): fix slash command detection when auto-create-thread is on#6293
dsocolobsky wants to merge 3 commits into
NousResearch:mainfrom
dsocolobsky:discord-fix-slash-commands-in-channel

Conversation

@dsocolobsky

Copy link
Copy Markdown
Contributor

What does this PR do?

Fixes text-based /slash commands (e.g. @bot /yolo, @bot /usage) not being recognized when sent via @mention in a Discord channel.

  • Previous:
image
  • After:
image

The root cause is that _auto_create_thread() can modify message.content after mention-stripping but before the /command detection check runs. This PR saves a copy of the mention-stripped text before auto-threading and uses that copy for command detection.

I've added tests that fail previous to this PR and pass after this PR, plus some required mock/fixture code to support them, I plan to expand on these tests in a separate PR since they're useful.

Related Issue

Fixes #5865

Type of Change

  • 🐛 Bug fix (non-breaking change that fixes an issue)

Changes Made

  • gateway/platforms/discord.py: Save mention-stripped content into normalized_content
    before _auto_create_thread() runs, and use it for /command detection and as event_text
    downstream.
  • tests/e2e/conftest.py: Add Discord mock setup, message factories, and adapter fixtures for
    e2e testing.
  • tests/e2e/test_discord_adapter.py: Add 6 e2e tests covering mention stripping, command
    dispatch, DMs, and the auto-threading content restoration bug.

How to Test

  1. Run hermes gateway via Discord
  2. In your home channel type @bot /yolo or @bot /usage
  3. Verify the command is recognized and returns the deterministic response (e.g. YOLO mode toggle), rather than being sent to the LLM

Checklist

Code

  • I've read the Contributing Guide
  • My commit messages follow Conventional Commits (fix(scope):, feat(scope):, etc.)
  • I searched for existing PRs to make sure this isn't a duplicate
  • My PR contains only changes related to this fix/feature (no unrelated commits)
  • I've run pytest tests/ -q and all tests pass
  • I've added tests for my changes (required for bug fixes, strongly encouraged for features)
  • I've tested on my platform: macOS 15.7

Documentation & Housekeeping

  • I've updated relevant documentation (README, docs/, docstrings) — or N/A
  • I've updated cli-config.yaml.example if I added/changed config keys — or N/A
  • I've updated CONTRIBUTING.md or AGENTS.md if I changed architecture or workflows — or N/A
  • I've considered cross-platform impact (Windows, macOS) per the compatibility guide — or N/A
  • I've updated tool descriptions/schemas if I changed tool behavior — or N/A

@dsocolobsky dsocolobsky changed the title Discord fix slash commands in channel fix(discord): fix slash command detection when auto-create-thread is on Apr 8, 2026
@dsocolobsky dsocolobsky force-pushed the discord-fix-slash-commands-in-channel branch from 11511d8 to 70b3713 Compare April 13, 2026 14:46
@trevorgordon981

Copy link
Copy Markdown

⚠️ Review - Test Failure Found

Tested in isolation - 5/6 tests passing, 1 failure

Test Results

Test Status
test_mention_then_command ✅ PASSED
test_nickname_mention_then_command ✅ PASSED
test_dm_no_mention_needed ✅ PASSED
test_no_mention_in_channel_dropped ✅ PASSED
test_command_detected_after_auto_thread ✅ PASSED
test_text_before_command_not_detected FAILED

Issue Found

**Test: ** ❌

Failure:

Root Cause: The test asserts that is called, but this is incorrect. When the message content is , the mention is stripped to , which doesn't start with , so it's treated as text, not a command. Text messages don't dispatch to the agent, so is never called.

Expected Behavior: The message should be accepted (not dropped), but no command output is produced, so should NOT be awaited.

Fix Needed: Remove or modify the assertion on line 61 of . The test should instead verify that:

  1. The message is accepted (not dropped)
  2. No command is dispatched (send is NOT called)

This is exactly the follow-up fix mentioned in PR #13187:

Fix test assertion for non-command text messages (no agent in mock = no send call)

Recommendation

Do not merge yet. This PR needs the follow-up fix:

Once this fix is applied, the PR is ready to merge. The core functionality (mention stripping + command detection) is working correctly - only the test assertion is wrong.


Reviewer: @teknium1
Tested on: macOS (Apple Silicon), Python 3.11.15
Date: April 20, 2026

@trevorgordon981

Copy link
Copy Markdown

✅ Fix Applied - All Tests Passing

Update: The test assertion issue has been fixed. All 6 tests now passing.

Fix Applied

File: (line 61)

Before:

After:

Test Results (After Fix)

Test Status
test_mention_then_command ✅ PASSED
test_nickname_mention_then_command ✅ PASSED
test_dm_no_mention_needed ✅ PASSED
test_no_mention_in_channel_dropped ✅ PASSED
test_command_detected_after_auto_thread ✅ PASSED
test_text_before_command_not_detected PASSED (was failing)

Recommendation

Ready to merge. The fix:

  1. Correctly verifies that text messages don't call
  2. All 6 tests passing
  3. Core functionality (mention stripping + command detection) working correctly

Reviewer: @teknium1
Tested on: macOS (Apple Silicon), Python 3.11.15
Date: April 20, 2026

teknium1 added a commit that referenced this pull request Apr 20, 2026
- Fix duplicate 'timezone' import in e2e conftest
- Fix test_text_before_command_not_detected asserting send() is awaited
  when no agent is present in mock setup (text messages don't produce
  command output)
@teknium1

Copy link
Copy Markdown
Contributor

Merged via PR #13187 (#13187). Your commits were cherry-picked onto current main with your authorship preserved in git log. Thanks @dsocolobsky!

@teknium1 teknium1 closed this Apr 20, 2026
ulasbilgen pushed a commit to ulasbilgen/hermes-adhd-agent that referenced this pull request May 1, 2026
…ousResearch#9091, NousResearch#13131

- Fix duplicate 'timezone' import in e2e conftest
- Fix test_text_before_command_not_detected asserting send() is awaited
  when no agent is present in mock setup (text messages don't produce
  command output)
aj-nt pushed a commit to aj-nt/hermes-agent that referenced this pull request May 1, 2026
…ousResearch#9091, NousResearch#13131

- Fix duplicate 'timezone' import in e2e conftest
- Fix test_text_before_command_not_detected asserting send() is awaited
  when no agent is present in mock setup (text messages don't produce
  command output)
Luminet2023 pushed a commit to Luminet2023/hermes-agent that referenced this pull request May 1, 2026
…ousResearch#9091, NousResearch#13131

- Fix duplicate 'timezone' import in e2e conftest
- Fix test_text_before_command_not_detected asserting send() is awaited
  when no agent is present in mock setup (text messages don't produce
  command output)
02356abc pushed a commit to 02356abc/hermes-agent that referenced this pull request May 14, 2026
…ousResearch#9091, NousResearch#13131

- Fix duplicate 'timezone' import in e2e conftest
- Fix test_text_before_command_not_detected asserting send() is awaited
  when no agent is present in mock setup (text messages don't produce
  command output)
gweeteve pushed a commit to gweeteve/hermes-agent that referenced this pull request Jun 2, 2026
…ousResearch#9091, NousResearch#13131

- Fix duplicate 'timezone' import in e2e conftest
- Fix test_text_before_command_not_detected asserting send() is awaited
  when no agent is present in mock setup (text messages don't produce
  command output)
Egavasyug pushed a commit to Egavasyug/hermes-agent that referenced this pull request Jun 10, 2026
…ousResearch#9091, NousResearch#13131

- Fix duplicate 'timezone' import in e2e conftest
- Fix test_text_before_command_not_detected asserting send() is awaited
  when no agent is present in mock setup (text messages don't produce
  command output)
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.

[Bug]: Discord /slash commands not being properly recognized when in channel

3 participants