Beta/commandes/salons/purge.py

28 lines
1.3 KiB
Python
Raw Normal View History

2026-02-06 22:23:20 +01:00
import discord
async def execute(bot, params, message):
purges = params.get('purges', [])
if not purges:
await message.channel.send("Aucune purge spécifiée.")
return
for purge in purges:
channel_name = purge.get('channel_name')
amount = purge.get('amount', 0)
if not channel_name or amount <= 0 or amount > 1000:
await message.channel.send(f"Purge invalide: canal '{channel_name}', quantité {amount} (max 1000).")
continue
channel = discord.utils.find(lambda c: c.name == channel_name, message.guild.channels)
if not channel or not isinstance(channel, discord.TextChannel):
await message.channel.send(f"Canal '{channel_name}' introuvable ou n'est pas un canal texte.")
continue
try:
deleted = await channel.purge(limit=amount, reason=f"Purge par {message.author}")
await message.channel.send(f"Supprimé {len(deleted)} message(s) dans {channel.mention}.")
except discord.Forbidden:
await message.channel.send(f"Je n'ai pas les permissions pour purger dans {channel.mention}.")
except Exception as e:
await message.channel.send(f"Erreur lors de la purge dans {channel.mention}: {str(e)}")