Files
.gitignore
bot.py
config.json
README.md
requirements.txt
Code
5 1,447
bot.py
import discord
from discord.ext import commands
import os
import asyncio
import json
import logging
from datetime import datetime, timedelta
from dotenv import load_dotenv
import aiohttp
from collections import defaultdict, deque
import time
load_dotenv()
logging.basicConfig(
level=logging.INFO,
format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',
handlers=[
logging.FileHandler('bot.log'),
logging.StreamHandler()
]
)
logger = logging.getLogger('SecurityBot')
intents = discord.Intents.all()
bot = commands.Bot(command_prefix='!', intents=intents, help_command=None)
bot.raid_detection = defaultdict(lambda: deque(maxlen=10))
bot.action_logs = defaultdict(lambda: deque(maxlen=50))
bot.whitelist = defaultdict(set)
bot.trusted_admins = defaultdict(set)
bot.server_configs = {}
bot.modmail_sessions = {}
bot.custom_commands = defaultdict(dict)
bot.backup_data = {}
bot.message_cache = defaultdict(lambda: deque(maxlen=1000))
bot.voice_logs = defaultdict(list)
bot.deleted_messages = defaultdict(lambda: deque(maxlen=500))
bot.edited_messages = defaultdict(lambda: deque(maxlen=500))
bot.antiraid_enabled = defaultdict(lambda: True)
bot.antinuke_enabled = defaultdict(lambda: True)
bot.security_level = defaultdict(lambda: 'high')
BANNER_URL = "https://i.imgur.com/dQjC5Qg.png"
BOT_NAME = "Advanced Security Bot"
BOT_VERSION = "3.5.0"
SUPPORT_SERVER = "https://discord.gg/yoursupportserver"
INVITE_LINK = "https://discord.com/api/oauth2/authorize?client_id=YOUR_BOT_ID&permissions=8&scope=bot"
def load_config():
try:
with open('config.json', 'r') as f:
return json.load(f)
except FileNotFoundError:
config = {
'prefix': '!',
'owners': [],
'banned_users': [],
'global_settings': {
'max_mentions': 5,
'max_joins_per_minute': 10,
'max_channel_creates': 3,
'max_role_creates': 3,
'max_kicks': 5,
'max_bans': 5,
'timeframe': 10
}
}
with open('config.json', 'w') as f:
json.dump(config, f, indent=4)
return config
def save_config(config):
with open('config.json', 'w') as f:
json.dump(config, f, indent=4)
config = load_config()
def get_user_position(member):
if member.guild.owner_id == member.id:
return "๐ Server Owner"
top_role = member.top_role
if member.guild_permissions.administrator:
return "๐ก๏ธ Administrator"
elif member.guild_permissions.manage_guild or member.guild_permissions.manage_roles:
return "โ๏ธ Staff Team"
elif member.guild_permissions.kick_members or member.guild_permissions.ban_members:
return "๐จ Moderator"
else:
return "๐ค Member"
async def notify_owner(guild, action_type, details, response_time=0):
owner = guild.owner
if not owner:
return
embed = discord.Embed(
title="๐จ Security Alert",
description=f"**Action Type:** {action_type}\n**Response Time:** {response_time:.2f}ms",
color=discord.Color.red(),
timestamp=datetime.utcnow()
)
embed.add_field(name="Details", value=details, inline=False)
embed.add_field(name="Server", value=guild.name, inline=True)
embed.add_field(name="Server ID", value=guild.id, inline=True)
embed.set_thumbnail(url=guild.icon.url if guild.icon else None)
embed.set_footer(text=f"{BOT_NAME} v{BOT_VERSION}")
try:
await owner.send(embed=embed)
except:
pass
async def log_action(guild, action, moderator, target, reason):
bot.action_logs[guild.id].append({
'action': action,
'moderator': str(moderator),
'target': str(target),
'reason': reason,
'timestamp': datetime.utcnow().isoformat()
})
class WelcomeView(discord.ui.View):
def __init__(self):
super().__init__(timeout=None)
@discord.ui.select(
placeholder="๐ Select an option...",
options=[
discord.SelectOption(
label="Commands & Help",
description="View all available commands",
emoji="๐",
value="help"
),
discord.SelectOption(
label="Support Server",
description="Join our support server",
emoji="๐ฌ",
value="support"
),
discord.SelectOption(
label="Security Features",
description="Learn about protection systems",
emoji="๐ก๏ธ",
value="features"
),
discord.SelectOption(
label="Quick Setup",
description="Get started quickly",
emoji="โก",
value="setup"
),
discord.SelectOption(
label="Premium Info",
description="Unlock advanced features",
emoji="โญ",
value="premium"
)
]
)
async def select_callback(self, interaction: discord.Interaction, select: discord.ui.Select):
if select.values[0] == "help":
embed = discord.Embed(
title="๐ Command List",
description="Here are all available commands:",
color=discord.Color.blue()
)
embed.add_field(
name="๐ก๏ธ Security Commands",
value="`!antinuke` - Toggle anti-nuke\n`!antiraid` - Toggle anti-raid\n`!whitelist <user>` - Whitelist user\n`!trust <user>` - Trust admin",
inline=False
)
embed.add_field(
name="๐จ Moderation Commands",
value="`!kick <user>` - Kick member\n`!ban <user>` - Ban member\n`!mute <user>` - Mute member\n`!warn <user>` - Warn member",
inline=False
)
embed.add_field(
name="๐ Utility Commands",
value="`!info` - Bot information\n`!serverinfo` - Server details\n`!userinfo <user>` - User details\n`!logs` - View action logs",
inline=False
)
embed.add_field(
name="๐พ Backup Commands",
value="`!backup create` - Create backup\n`!backup restore` - Restore backup\n`!backup list` - List backups",
inline=False
)
embed.add_field(
name="๐จ Custom Commands",
value="`!cc add <name> <response>` - Add custom command\n`!cc remove <name>` - Remove command\n`!cc list` - List custom commands",
inline=False
)
embed.set_image(url=BANNER_URL)
await interaction.response.send_message(embed=embed, ephemeral=True)