Voice et bot modif

This commit is contained in:
pi 2026-06-16 17:09:34 +00:00
parent 189d56026b
commit 7333a22bcd
10774 changed files with 634644 additions and 933308 deletions

View file

@ -1,5 +1,22 @@
import discord
async def _find_channel(guild, channel_params):
"""Find a channel by ID first, then by name (case-insensitive)."""
channel_id = channel_params.get('channel_id')
if channel_id:
try:
ch = guild.get_channel(int(channel_id))
if ch:
return ch
except (ValueError, TypeError):
pass
channel_name = channel_params.get('channel_name')
if not channel_name:
return None
return discord.utils.find(lambda c: c.name.casefold() == channel_name.casefold(), guild.channels)
async def execute(bot, params, message):
channels = params.get('channels', [])
if not channels:
@ -9,15 +26,27 @@ async def execute(bot, params, message):
renamed_count = 0
for channel_params in channels:
channel_name = channel_params.get('channel_name')
new_name = channel_params.get('new_name')
channel = discord.utils.find(lambda c: c.name.casefold() == channel_name.casefold(), guild.channels)
# Support both 'new_name' and 'new_channel_name' variants
new_name = channel_params.get('new_name') or channel_params.get('new_channel_name')
channel = await _find_channel(guild, channel_params)
if not channel:
await message.channel.send(f"Salon '{channel_name}' introuvable.")
label = channel_name or channel_params.get('channel_id', 'inconnu')
await message.channel.send(f"Salon '{label}' introuvable.")
continue
if not new_name:
await message.channel.send("Aucun nouveau nom spécifié pour le renommage.")
continue
try:
await channel.edit(name=new_name)
renamed_count += 1
except discord.Forbidden:
await message.channel.send(f"Je n'ai pas les permissions pour renommer le salon '{channel_name}'.")
label = channel_name or channel_params.get('channel_id', 'inconnu')
await message.channel.send(f"Je n'ai pas les permissions pour renommer le salon '{label}'.")
except Exception as e:
label = channel_name or channel_params.get('channel_id', 'inconnu')
await message.channel.send(f"Erreur lors du renommage du salon '{label}': {e}")
if renamed_count > 0:
await message.channel.send(f"{renamed_count} salon(s) renommé(s).")
await message.channel.send(f"{renamed_count} salon(s) renommé(s).")