Beta/commandes/salons/creer.py

43 lines
2 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')
category_name = channel_params.get('category_name')
channel_type = channel_params.get('channel_type', 'textuel')
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
else:
category = None
try:
if channel_type.casefold() == 'textuel':
channel = await guild.create_text_channel(channel_name, category=category)
elif channel_type.casefold() == 'vocal':
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:
await message.channel.send(f"{created_count} salon(s) créé(s).")