Summary
Currently the bot responds to messages in any thread across the entire server, not just threads that belong to the configured channel. This is a bug that needs to be fixed now, with a future enhancement to support tag-based triggering when the bot is deployed across multiple repos/servers.
Identified in: #6 (comment)
Related PR: #6
Requested by: @kpj2006
Bug: Bot responds to ALL threads server-wide
Root Cause
In bot.py, the guard in process_message has a logic flaw:
is_in_thread = isinstance(message.channel, discord.Thread)
is_in_configured_channel = message.channel.id == DISCORD_CHANNEL_ID_INT
if not is_in_thread and not is_in_configured_channel:
return
When message.channel is a discord.Thread, its .id is the thread's own ID, not the parent channel's ID. The condition not is_in_thread and not is_in_configured_channel lets all threads pass regardless of which channel they belong to, because is_in_thread being True skips the channel ID check entirely.
Fix for Current Codebase
In bot.py, update the process_message function (around lines 169–173):
is_in_thread = isinstance(message.channel, discord.Thread)
- is_in_configured_channel = message.channel.id == DISCORD_CHANNEL_ID_INT
+ if is_in_thread:
+ is_in_configured_channel = message.channel.parent_id == DISCORD_CHANNEL_ID_INT
+ else:
+ is_in_configured_channel = message.channel.id == DISCORD_CHANNEL_ID_INT
- if not is_in_thread and not is_in_configured_channel:
+ if not is_in_configured_channel:
return
This uses message.channel.parent_id when the channel is a Thread, which correctly identifies the parent text channel.
Future Enhancement: Tag-based Triggering Across Repos
In a later phase, the bot will be deployed across multiple Discord servers/repos and should only respond when explicitly mentioned/tagged (e.g., @SkillBot <question>).
Changes needed when implementing this:
-
Add mention detection in process_message:
- Check if
client.user is mentioned in message.mentions before processing.
- Strip the mention prefix from the message content before passing it to Ollama.
-
Remove or relax the single-channel restriction (DISCORD_CHANNEL_ID_INT check):
- Once tag-based triggering is in place, the bot can safely listen server-wide (or across guilds) since it only activates on explicit mentions.
-
Update _get_or_create_thread:
- Thread naming / parent channel logic may need to be generalized to work across any channel.
-
Update .env / configuration:
DISCORD_CHANNEL_ID can be made optional or replaced with a list of allowed channels/guilds.
-
Update on_ready backlog processing:
- Backlog catch-up should also filter by mentions to avoid re-processing unrelated messages.
Summary
Currently the bot responds to messages in any thread across the entire server, not just threads that belong to the configured channel. This is a bug that needs to be fixed now, with a future enhancement to support tag-based triggering when the bot is deployed across multiple repos/servers.
Identified in: #6 (comment)
Related PR: #6
Requested by: @kpj2006
Bug: Bot responds to ALL threads server-wide
Root Cause
In
bot.py, the guard inprocess_messagehas a logic flaw:When
message.channelis adiscord.Thread, its.idis the thread's own ID, not the parent channel's ID. The conditionnot is_in_thread and not is_in_configured_channellets all threads pass regardless of which channel they belong to, becauseis_in_threadbeingTrueskips the channel ID check entirely.Fix for Current Codebase
In
bot.py, update theprocess_messagefunction (around lines 169–173):This uses
message.channel.parent_idwhen the channel is aThread, which correctly identifies the parent text channel.Future Enhancement: Tag-based Triggering Across Repos
In a later phase, the bot will be deployed across multiple Discord servers/repos and should only respond when explicitly mentioned/tagged (e.g.,
@SkillBot <question>).Changes needed when implementing this:
Add mention detection in
process_message:client.useris mentioned inmessage.mentionsbefore processing.Remove or relax the single-channel restriction (
DISCORD_CHANNEL_ID_INTcheck):Update
_get_or_create_thread:Update
.env/ configuration:DISCORD_CHANNEL_IDcan be made optional or replaced with a list of allowed channels/guilds.Update
on_readybacklog processing: