Beta/commandes/salons/creer.py

47 lines
2.1 KiB
Python
Raw Permalink Normal View History

2026-02-06 22:23:20 +01:00
import discord
async def execute(bot, params, message):
channels = params.get('channels', [])
if not channels:
# Fallback for single channel
channels = [params]
guild = message.guild
created_count = 0
for channel_params in channels:
channel_name = channel_params.get('channel_name')
2026-06-16 17:09:34 +00:00
if not channel_name:
await message.channel.send("Nom de salon requis pour la création.")
continue
2026-02-06 22:23:20 +01:00
category_name = channel_params.get('category_name')
2026-06-16 17:09:34 +00:00
channel_type = (channel_params.get('channel_type') or 'textuel').casefold()
category = None
2026-02-06 22:23:20 +01:00
if category_name:
# Recherche flexible : trouver une catégorie dont le nom contient le terme recherché
category = discord.utils.find(
lambda cat: category_name.casefold() in cat.name.casefold(),
guild.categories
)
if not category:
# Create the category if it doesn't exist
try:
category = await guild.create_category(category_name)
await message.channel.send(f"Catégorie '{category_name}' créée.")
except discord.Forbidden:
await message.channel.send(f"Je n'ai pas les permissions pour créer la catégorie '{category_name}'.")
continue
2026-06-16 17:09:34 +00:00
2026-02-06 22:23:20 +01:00
try:
2026-06-16 17:09:34 +00:00
if channel_type == 'textuel':
2026-02-06 22:23:20 +01:00
channel = await guild.create_text_channel(channel_name, category=category)
2026-06-16 17:09:34 +00:00
elif channel_type == 'vocal':
2026-02-06 22:23:20 +01:00
channel = await guild.create_voice_channel(channel_name, category=category)
else:
await message.channel.send(f"Type de salon invalide pour '{channel_name}'. Utilisez 'textuel' ou 'vocal'.")
continue
created_count += 1
except discord.Forbidden:
await message.channel.send(f"Je n'ai pas les permissions pour créer le salon '{channel_name}'.")
if created_count > 0:
2026-06-16 17:09:34 +00:00
await message.channel.send(f"{created_count} salon(s) créé(s).")