Untitled
unknown
plain_text
a year ago
1.9 kB
8
Indexable
import discord
from discord.ext import commands
from collections import defaultdict
from datetime import datetime, timedelta
intents = discord.Intents.default()
intents.guilds = True
intents.members = True
intents.bans = True
bot = commands.Bot(command_prefix="!", intents=intents)
# Dictionary to track ban actions and their timestamps
ban_tracker = defaultdict(list)
# Quarantine role name
QUARANTINE_ROLE_NAME = "Quarantined"
@bot.event
async def on_ready():
print(f"Logged in as {bot.user}")
@bot.event
async def on_member_ban(guild, user):
# Fetch the audit log to get the user who performed the ban
audit_logs = await guild.audit_logs(limit=1, action=discord.AuditLogAction.ban).flatten()
ban_entry = audit_logs[0]
banner = ban_entry.user
now = datetime.utcnow()
# Record the time of the ban
ban_tracker[banner.id].append(now)
# Clean up old entries that are older than 10 seconds
ban_tracker[banner.id] = [t for t in ban_tracker[banner.id] if now - t <= timedelta(seconds=10)]
# Check if the user has banned more than 5 members in the last 10 seconds
if len(ban_tracker[banner.id]) > 5:
# Attempt to quarantine the user
quarantine_role = discord.utils.get(guild.roles, name=QUARANTINE_ROLE_NAME)
if quarantine_role:
await banner.add_roles(quarantine_role)
print(f"{banner.name} has been quarantined for banning more than 5 members within 10 seconds.")
else:
print(f"Quarantine role '{QUARANTINE_ROLE_NAME}' not found. Unable to quarantine {banner.name}.")
# Optionally, log or notify about the quarantine action here
@bot.event
async def on_guild_role_create(role):
# Automatically create quarantine role if it doesn't exist
if role.name == QUARANTINE_ROLE_NAME:
print(f"Quarantine role '{QUARANTINE_ROLE_NAME}' has been created.")
bot.run('YOUR_BOT_TOKEN')
Editor is loading...
Leave a Comment