Skip to content

Commit 06f60f8

Browse files
drpedapaticlaude
andcommitted
fix(discord): detect role mentions in addition to user mentions
Previously, only direct @user mentions were detected. When a user @mentioned a role that the bot has, Discord puts it in MentionRoles not Mentions, so the bot would ignore messages with role mentions. Now checks both: - Direct user mentions (m.Mentions) - Role mentions where bot has that role (m.MentionRoles + GuildMember lookup) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent c0fadba commit 06f60f8

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

pkg/channels/discord.go

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -257,15 +257,32 @@ func (c *DiscordChannel) handleMessage(s *discordgo.Session, m *discordgo.Messag
257257
senderName += "#" + m.Author.Discriminator
258258
}
259259

260-
// Detect @bot mention
260+
// Detect @bot mention (direct user mention OR role mention)
261261
isMention := m.GuildID == "" // DMs are always "mentions"
262262
if !isMention {
263+
// Check direct user mentions
263264
for _, u := range m.Mentions {
264265
if u.ID == c.botUserID {
265266
isMention = true
266267
break
267268
}
268269
}
270+
// Check role mentions - if user mentioned any role, check if bot has that role
271+
if !isMention && len(m.MentionRoles) > 0 && m.GuildID != "" {
272+
if member, err := s.GuildMember(m.GuildID, c.botUserID); err == nil {
273+
for _, mentionedRole := range m.MentionRoles {
274+
for _, botRole := range member.Roles {
275+
if mentionedRole == botRole {
276+
isMention = true
277+
break
278+
}
279+
}
280+
if isMention {
281+
break
282+
}
283+
}
284+
}
285+
}
269286
}
270287

271288
content := m.Content

0 commit comments

Comments
 (0)