import discord from discord.ext import commands from discord.ui import View, Button from .loader import ModerationBase class WarnCommand(ModerationBase): @commands.command(name="warn") @ModerationBase.is_admin() async def warn(self, ctx, user: discord.Member, *, reason: str = None): """Warn a user with confirmation and log infraction""" view = View(timeout=30) confirmed = {"value": False} async def yes_callback(interaction: discord.Interaction): if interaction.user != ctx.author: await interaction.response.send_message("You can't confirm this action.", ephemeral=True) return confirmed["value"] = True await interaction.response.edit_message(content="✅ Confirmed.", view=None) view.stop() async def no_callback(interaction: discord.Interaction): if interaction.user != ctx.author: await interaction.response.send_message("You can't cancel this action.", ephemeral=True) return confirmed["value"] = False await interaction.response.edit_message(content="❌ Cancelled.", view=None) view.stop() yes_button = Button(label="Yes", style=discord.ButtonStyle.green) no_button = Button(label="No", style=discord.ButtonStyle.red) yes_button.callback = yes_callback no_button.callback = no_callback view.add_item(yes_button) view.add_item(no_button) await ctx.send(f"Are you sure you want to warn {user.mention}? Reason: {reason or 'No reason provided'}", view=view) await view.wait() if not confirmed["value"]: return try: await user.send(f"You have been **warned** in **{ctx.guild.name}**.\nReason: {reason or 'No reason provided'}") except: await ctx.send("Could not DM the user.") await self.log_infraction(ctx.guild.id, user.id, ctx.author.id, "warn", reason) await ctx.send(f"{user.mention} has been warned.") # Log to logging system logger = self.bot.get_cog("Logger") if logger: await logger.log_moderation_action( ctx.guild.id, "warn", user, ctx.author, reason ) async def setup(bot: commands.Bot): await bot.add_cog(WarnCommand(bot))