Add exempt_users config to skip muting specific users
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -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
|
||||
|
||||
|
||||
+2
-1
@@ -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"]
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user