import discord from discord.ext import commands from discord.ui import Button, View import json import os import threading from http.server import SimpleHTTPRequestHandler, HTTPServer # --- MINI SERVIDOR WEB PARA QUE LA NUBE GRATUITA NO LO APAGUE --- def run_web_server(): server_address = ('0.0.0.0', 7860) httpd = HTTPServer(server_address, SimpleHTTPRequestHandler) httpd.serve_forever() threading.Thread(target=run_web_server, daemon=True).start() # --- CÓDIGO DE TU BOT INTEGRAL --- intents = discord.Intents.default() intents.message_content = True intents.members = True bot = commands.Bot(command_prefix="!", intents=intents) DATA_FILE = "historial_mod.json" def cargar_datos(): if os.path.exists(DATA_FILE): with open(DATA_FILE, "r") as f: return json.load(f) return {} def guardar_datos(datos): with open(DATA_FILE, "w") as f: json.dump(datos, f, indent=4) class PanelModeracion(View): def __init__(self, target_member: discord.Member, autor_del_comando: discord.User): super().__init__(timeout=None) self.target_member = target_member self.autor_del_comando = autor_del_comando self.historial = cargar_datos() str_id = str(target_member.id) if str_id not in self.historial: self.historial[str_id] = {"avisos": 0, "strikes": 0} guardar_datos(self.historial) async def interaction_check(self, interaction: discord.Interaction) -> bool: if interaction.user.id != self.autor_del_comando.id: await interaction.response.send_message( f"❌ Este panel pertenece a <@{self.autor_del_comando.id}>. Para moderar tú, pon tu propio comando `!mod`.", ephemeral=True ) return False return True def obtener_estado(self): datos = self.historial[str(self.target_member.id)] return f"👤 **Usuario:** {self.target_member.mention}\n⚠️ **Avisos:** {datos['avisos']}/3 | 🚫 **Strikes:** {datos['strikes']}/3" @discord.ui.button(label="⚠️ +1 Aviso", style=discord.ButtonStyle.blurple) async def boton_aviso(self, interaction: discord.Interaction, button: Button): str_id = str(self.target_member.id) self.historial[str_id]["avisos"] += 1 msg_extra = "" if self.historial[str_id]["avisos"] >= 3: self.historial[str_id]["avisos"] = 0 self.historial[str_id]["strikes"] += 1 msg_extra = "\n🔄 ¡3 Avisos se han convertido en 1 Strike!" guardar_datos(self.historial) try: await self.target_member.send(f"⚠️ Has recibido un aviso formal en el servidor.") except: pass embed = discord.Embed(title="Moderación Actualizada", description=f"Aviso procesado para {self.target_member.mention}.{msg_extra}\n\n{self.obtener_estado()}", color=discord.Color.gold()) await interaction.response.edit_message(embed=embed, view=self) @discord.ui.button(label="💥 +1 Strike", style=discord.ButtonStyle.danger) async def boton_strike(self, interaction: discord.Interaction, button: Button): str_id = str(self.target_member.id) self.historial[str_id]["strikes"] += 1 guardar_datos(self.historial) try: await self.target_member.send(f"🚫 ¡Has recibido un Strike! Llevas {self.historial[str_id]['strikes']}/3.") except: pass embed = discord.Embed(title="💥 Strike Registrado", description=f"{self.target_member.mention} ha recibido un strike.\n\n{self.obtener_estado()}", color=discord.Color.orange()) if self.historial[str_id]["strikes"] >= 3: try: await self.target_member.ban(reason="Acumulación de 3 strikes.") embed.description += "\n\n🚨 **¡BANEADO automáticamente por alcanzar 3 strikes!**" embed.color = discord.Color.red() for child in self.children: child.disabled = True except: embed.description += "\n\n❌ Falló el Ban automático (revisa los permisos del bot)." await interaction.response.edit_message(embed=embed, view=self) @discord.ui.button(label="❌ Resetear", style=discord.ButtonStyle.grey) async def boton_reset(self, interaction: discord.Interaction, button: Button): str_id = str(self.target_member.id) self.historial[str_id] = {"avisos": 0, "strikes": 0} guardar_datos(self.historial) embed = discord.Embed(title="🔄 Historial Limpiado", description=f"Contadores a cero para {self.target_member.mention}.\n\n{self.obtener_estado()}", color=discord.Color.green()) await interaction.response.edit_message(embed=embed, view=self) @bot.command(name="mod") @commands.has_permissions(manage_messages=True) async def panel_mod(ctx, member: discord.Member): view = PanelModeracion(member, ctx.author) embed = discord.Embed(title="🛡️ Panel de Control de Personal", description=view.obtener_estado(), color=discord.Color.blue()) await ctx.send(embed=embed, view=view) bot.run('MTU0ODYyNzcwNTkzNzc4ODk2OA.GFIIa4.8sJOH8rGLg521uJCbLT_rNHSC7-ekZxHsGnrZE')