import discord from discord import app_commands from discord.ext import commands import asyncio import json intents = discord.Intents.default() intents.message_content = True intents.guilds = True intents.members = True bot = commands.Bot(intents=intents) config = { "slowmode_duration": 20, "affected_roles": [], } def save_config(): with open("config.json", "w") as f: json.dump(config, f) def load_config(): global config try: with open("config.json", "r") as f: config = json.load(f) except FileNotFoundError: save_config() @bot.event async def on_ready(): print(f"{bot.user} est en ligne.") load_config() try: synced = await bot.tree.sync() print(f"Commands synced: {len(synced)}") except Exception as e: print(f"Erreur lors de la sync des commandes : {e}") @bot.tree.command(name="setslowmode", description="Définit la durée du slowmode dans les threads (en minutes)") @app_commands.checks.has_permissions(manage_threads=True) @app_commands.describe(minutes="Durée du slowmode en minutes") async def setslowmode(interaction: discord.Interaction, minutes: int): config["slowmode_duration"] = minutes save_config() updated_threads = 0 failed_threads = [] for thread in interaction.guild.threads: if not thread.archived: try: await thread.edit(slowmode_delay=minutes*60) updated_threads += 1 except Exception as e: failed_threads.append(thread.name) message = f"✅ Slowmode par défaut défini à {seconds} minutes.\n" message += f"🧵 Slowmode mis à jour dans {updated_threads} thread(s)." if failed_threads: message += f"\n⚠️ Impossible de modifier : {', '.join(failed_threads)}" await interaction.response.send_message(message, ephemeral=True) @bot.tree.command(name="help", description="Affiche la liste des commandes disponibles") async def help_command(interaction: discord.Interaction): help_text = """ **📋 Commandes Slash :** - `/setslowmode ` : Définit la durée du slowmode dans les threads. - `/help` : Affiche cette aide. """ await interaction.response.send_message(help_text, ephemeral=True) @bot.event async def on_thread_create(thread): try: await thread.edit(slowmode_delay=config["slowmode_duration"]) print(f"✅ Slowmode de {config['slowmode_duration']}s appliqué à {thread.name}") except Exception as e: print(f"❌ Impossible de définir le slowmode sur {thread.name} : {e}") @bot.tree.error async def on_app_command_error(interaction: discord.Interaction, error): if isinstance(error, app_commands.MissingPermissions): await interaction.response.send_message("❌ Permissions insuffisantes pour cette commande.", ephemeral=True) else: await interaction.response.send_message(f"❌ Une erreur est survenue : {error}", ephemeral=True) print(f"Erreur commande slash : {error}") bot.run("MTM4MTk4ODA2NjUwMzQzMDI0Nw.G_7FMX.DMZ32kmoTHRnGHaQ1TEc_o1EwHAt-Tvkkb-ADQ")