import discord from discord.ext import commands from discord.ui import Button, Select, View import re # Bot setup intents = discord.Intents.default() intents.messages = True intents.message_content = True bot = commands.Bot(command_prefix="$", intents=intents) # Automod Configuration automod_config = { "anti_spam": {"enabled": False, "action": "warn"}, "anti_link": {"enabled": False, "action": "delete"}, "anti_swear": {"enabled": False, "action": "warn"}, "anti_self_commands": {"enabled": False, "action": "warn"}, "blocked_words": [] } # Command: Auto-setup @bot.command() async def auto_setup(ctx): # Create buttons for toggling each feature class AutoModSetup(View): @discord.ui.button(label="Anti-Spam", style=discord.ButtonStyle.green, custom_id="anti_spam") async def toggle_anti_spam(self, interaction: discord.Interaction, button: Button): automod_config["anti_spam"]["enabled"] = not automod_config["anti_spam"]["enabled"] status = "enabled" if automod_config["anti_spam"]["enabled"] else "disabled" await interaction.response.send_message(f"Anti-Spam has been {status}.", ephemeral=True) @discord.ui.button(label="Anti-Link", style=discord.ButtonStyle.green, custom_id="anti_link") async def toggle_anti_link(self, interaction: discord.Interaction, button: Button): automod_config["anti_link"]["enabled"] = not automod_config["anti_link"]["enabled"] status = "enabled" if automod_config["anti_link"]["enabled"] else "disabled" await interaction.response.send_message(f"Anti-Link has been {status}.", ephemeral=True) @discord.ui.button(label="Anti-Swear", style=discord.ButtonStyle.green, custom_id="anti_swear") async def toggle_anti_swear(self, interaction: discord.Interaction, button: Button): automod_config["anti_swear"]["enabled"] = not automod_config["anti_swear"]["enabled"] status = "enabled" if automod_config["anti_swear"]["enabled"] else "disabled" await interaction.response.send_message(f"Anti-Swear has been {status}.", ephemeral=True) @discord.ui.button(label="Anti-Self Commands", style=discord.ButtonStyle.green, custom_id="anti_self_commands") async def toggle_anti_self_commands(self, interaction: discord.Interaction, button: Button): automod_config["anti_self_commands"]["enabled"] = not automod_config["anti_self_commands"]["enabled"] status = "enabled" if automod_config["anti_self_commands"]["enabled"] else "disabled" await interaction.response.send_message(f"Anti-Self Commands has been {status}.", ephemeral=True) @discord.ui.button(label="Set Blocked Words", style=discord.ButtonStyle.blurple, custom_id="set_blocked_words") async def set_blocked_words(self, interaction: discord.Interaction, button: Button): await interaction.response.send_message( "Reply with a comma-separated list of words to block. Example: `word1, word2, word3`", ephemeral=True ) def check(msg): return msg.author == interaction.user and msg.channel == interaction.channel try: msg = await bot.wait_for("message", timeout=30.0, check=check) automod_config["blocked_words"] = [word.strip().lower() for word in msg.content.split(",")] await interaction.followup.send(f"Blocked words updated: {', '.join(automod_config['blocked_words'])}", ephemeral=True) except asyncio.TimeoutError: await interaction.followup.send("You didn't reply in time.", ephemeral=True) view = AutoModSetup() await ctx.send("Configure AutoMod settings using the buttons below:", view=view) # AutoMod Check @bot.event async def on_message(message): if message.author.bot: return # Check for blocked words if automod_config["anti_swear"]["enabled"]: for word in automod_config["blocked_words"]: if word in message.content.lower(): await handle_violation(message, automod_config["anti_swear"]["action"], "swearing") return # Check for spam (simple repetition check) if automod_config["anti_spam"]["enabled"]: if len(message.content) > 200 or message.content.count(message.content[:10]) > 5: # Simplistic spam detection await handle_violation(message, automod_config["anti_spam"]["action"], "spamming") return # Check for links if automod_config["anti_link"]["enabled"]: if re.search(r"https?://\S+", message.content): await handle_violation(message, automod_config["anti_link"]["action"], "posting links") return # Check for self-promotion commands if automod_config["anti_self_commands"]["enabled"]: if message.content.startswith("!"): await handle_violation(message, automod_config["anti_self_commands"]["action"], "using self commands") return await bot.process_commands(message) # Handle violations async def handle_violation(message, action, violation_type): if action == "warn": await message.channel.send(f"{message.author.mention}, you have been warned for {violation_type}.") elif action == "delete": await message.delete() await message.channel.send(f"{message.author.mention}, your message was deleted for {violation_type}.") elif action == "ban": await message.guild.ban(message.author, reason=f"Automod: {violation_type}") await message.channel.send(f"{message.author.mention} has been banned for {violation_type}.") # Run the bot bot.run("YOUR_BOT_TOKEN")