Füge Mute-Cooldown-Logik hinzu: Implementiere Datenstruktur für Mute-Cooldowns zur Vermeidung von Spam

This commit is contained in:
2026-02-20 17:38:44 +01:00
parent 972d765712
commit fa2b2f8d27

10
bot.py
View File

@@ -12,6 +12,7 @@ load_dotenv()
TOKEN = os.getenv("DISCORD_TOKEN")
MILESTONE_CHANNEL_ID = int(os.getenv("MILESTONE_CHANNEL_ID", 0))
DATA_FILE = "data.json"
MUTE_COOLDOWN = 5.0 # Sekunden zwischen zwei zählbaren Mutes pro Nutzer
# ---------------------------------------------------------------------------
# Konfiguration
@@ -355,6 +356,7 @@ intents.members = True
bot = commands.Bot(command_prefix="!", intents=intents)
mute_data = load_data()
voice_sessions: dict[tuple[int, int], float] = {}
mute_cooldowns: dict[tuple[int, int], float] = {} # (guild_id, user_id) → letzter Mute-Timestamp
@tasks.loop(hours=1)
@@ -428,6 +430,14 @@ async def on_voice_state_update(member: discord.Member,
if not just_deafened and not just_mic_muted:
return
# Spam-Schutz: Mute innerhalb des Cooldowns wird nicht gezählt
key = (guild.id, member.id)
now = time.time()
if now - mute_cooldowns.get(key, 0.0) < MUTE_COOLDOWN:
print(f"[SKIP ] {member.display_name} — Cooldown aktiv [{guild.name}]")
return
mute_cooldowns[key] = now
kind = "deaf" if just_deafened else "mic"
old_lb = get_sorted_lb(mute_data, guild.id)