Skip to content

fix(discord): require thread ID for forum channels to prevent broadcast#522

Merged
ptone merged 2 commits into
GoogleCloudPlatform:mainfrom
ptone:scion/fix-discord-forum-broadcast
Jun 28, 2026
Merged

fix(discord): require thread ID for forum channels to prevent broadcast#522
ptone merged 2 commits into
GoogleCloudPlatform:mainfrom
ptone:scion/fix-discord-forum-broadcast

Conversation

@ptone

@ptone ptone commented Jun 28, 2026

Copy link
Copy Markdown
Member

Fixes : Discord forum channels were broadcasting messages to all threads when thread ID was omitted. Now validates channel type and requires thread ID for forum channels.

@google-cla

google-cla Bot commented Jun 28, 2026

Copy link
Copy Markdown

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces a guard in the Discord broker's Publish method to prevent sending messages directly to forum and media channels without a thread ID, returning an error instead. It also adds a helper method isForumChannel to identify these channel types and includes comprehensive unit tests. Feedback was provided to add a nil check on the channel object returned from the Discord session API call to prevent a potential nil pointer dereference panic.

Comment on lines +1282 to +1285
ch, err = session.Channel(channelID)
if err != nil {
return false
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

To prevent a potential nil pointer dereference panic, defensively check if ch is nil after calling session.Channel(channelID) before accessing ch.Type.

Suggested change
ch, err = session.Channel(channelID)
if err != nil {
return false
}
ch, err = session.Channel(channelID)
if err != nil || ch == nil {
return false
}

Scion Agent (mi-dev-c) added 2 commits June 28, 2026 12:01
Discord forum (type 15) and media (type 16) channels are thread-only
containers that cannot receive messages directly. When a message was
routed to one of these channels without a thread ID, the broker would
attempt to send to the container channel itself, which could broadcast
unintentionally. Now the Publish method detects forum/media channel
targets and returns a clear error asking the caller to specify a
thread ID.

Also fixes an incorrect comment that labeled GuildNewsThread as type 15
(it is type 10; type 15 is GuildForum).

Closes #290
After calling session.Channel(channelID), ch could be nil even without
an error. Add nil check to prevent panic when accessing ch.Type.
@ptone ptone force-pushed the scion/fix-discord-forum-broadcast branch from 257e6f4 to 7f85e68 Compare June 28, 2026 12:01
@ptone ptone merged commit b4a682a into GoogleCloudPlatform:main Jun 28, 2026
7 of 9 checks passed
@ptone ptone deleted the scion/fix-discord-forum-broadcast branch June 28, 2026 12:11
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