From cecd50361c9e03d672b76e6b53a352d44bb66c97 Mon Sep 17 00:00:00 2001 From: Richard Aasa Date: Mon, 1 Jun 2026 18:02:30 +0300 Subject: [PATCH] Add exempt_users config to skip muting specific users Co-Authored-By: Claude Sonnet 4.6 --- README.md | 7 +++++-- config.json | 3 ++- main.go | 15 ++++++++++----- 3 files changed, 17 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 071f311..8e816c5 100644 --- a/README.md +++ b/README.md @@ -17,11 +17,14 @@ Runs in the system tray as a console app. Press a configurable global hotkey to "token": "YOUR_BOT_TOKEN", "guild_id": "YOUR_SERVER_ID", "channel_id": "YOUR_VOICE_CHANNEL_ID", - "keybind": "ctrl+shift+m" + "keybind": "ctrl+shift+m", + "exempt_users": ["YOUR_DISCORD_USER_ID"] } ``` -To get IDs: enable **Developer Mode** in Discord settings, then right-click a server or channel and choose **Copy ID**. +`exempt_users` is optional. Any user IDs listed there will never be muted. Add your own ID to exclude yourself when pressing the keybind. + +To get IDs: enable **Developer Mode** in Discord settings, then right-click a server, channel, or user and choose **Copy ID**. ## Keybind format diff --git a/config.json b/config.json index d4bf7ba..3df433b 100644 --- a/config.json +++ b/config.json @@ -2,5 +2,6 @@ "token": "YOUR_BOT_TOKEN_HERE", "guild_id": "YOUR_SERVER_ID", "channel_id": "YOUR_VOICE_CHANNEL_ID", - "keybind": "ctrl+shift+m" + "keybind": "ctrl+shift+m", + "exempt_users": ["YOUR_DISCORD_USER_ID"] } diff --git a/main.go b/main.go index 3706a74..51deed0 100644 --- a/main.go +++ b/main.go @@ -14,10 +14,11 @@ import ( ) type Config struct { - Token string `json:"token"` - GuildID string `json:"guild_id"` - ChannelID string `json:"channel_id"` - Keybind string `json:"keybind"` + Token string `json:"token"` + GuildID string `json:"guild_id"` + ChannelID string `json:"channel_id"` + Keybind string `json:"keybind"` + ExemptUsers []string `json:"exempt_users"` } func loadConfig() (*Config, error) { @@ -103,9 +104,13 @@ func toggleMute(dg *discordgo.Session, cfg *Config, muted bool) { log.Printf("guild not in state cache (is the bot in the server?): %v", err) return } + exempt := make(map[string]bool, len(cfg.ExemptUsers)) + for _, id := range cfg.ExemptUsers { + exempt[id] = true + } count := 0 for _, vs := range guild.VoiceStates { - if vs.ChannelID == cfg.ChannelID { + if vs.ChannelID == cfg.ChannelID && !exempt[vs.UserID] { if err := dg.GuildMemberMute(cfg.GuildID, vs.UserID, muted); err != nil { log.Printf(" warning: user %s: %v", vs.UserID, err) }