Ajout de la commande !say pour permettre l'envoi de messages en tant que bot dans un canal spécifié, avec des instructions d'utilisation .

This commit is contained in:
Mow
2025-11-11 22:38:22 +01:00
parent a0a14abf57
commit cb559c2863
2 changed files with 61 additions and 1 deletions

View File

@@ -18,7 +18,8 @@ from discordbot.moderation import (
handle_inspect_command, handle_inspect_command,
handle_ban_list_command, handle_ban_list_command,
handle_staff_help_command, handle_staff_help_command,
handle_timeout_command handle_timeout_command,
handle_say_command
) )
from discordbot.welcome import sendWelcomeMessage, sendLeaveMessage, updateInviteCache from discordbot.welcome import sendWelcomeMessage, sendLeaveMessage, updateInviteCache
from protondb import searhProtonDb from protondb import searhProtonDb
@@ -136,6 +137,10 @@ async def on_message(message: Message):
await handle_inspect_command(message, bot) await handle_inspect_command(message, bot)
return return
if command_name == '!say':
await handle_say_command(message, bot)
return
if command_name in ['!aide', '!help']: if command_name in ['!aide', '!help']:
await handle_staff_help_command(message, bot) await handle_staff_help_command(message, bot)
return return

View File

@@ -1050,6 +1050,16 @@ async def handle_staff_help_command(message: Message, bot):
) )
embed.add_field(name="👢 Expulsion", value=value, inline=False) embed.add_field(name="👢 Expulsion", value=value, inline=False)
embed.add_field(
name="💬 Autres",
value=(
"• `!say #channel message`\n"
" Envoie un message en tant que bot\n"
" Ex: `!say #annonces Nouvelle fonctionnalité !`"
),
inline=False
)
try: try:
sent = await message.channel.send(embed=embed) sent = await message.channel.send(embed=embed)
if is_staff: if is_staff:
@@ -1335,3 +1345,48 @@ async def handle_inspect_command(message: Message, bot):
await message.channel.send(embed=embed) await message.channel.send(embed=embed)
await safe_delete_message(message) await safe_delete_message(message)
async def handle_say_command(message: Message, bot):
if not has_staff_role(message.author.roles):
await send_access_denied(message.channel)
return
parts = message.content.split(maxsplit=2)
if len(parts) < 3:
embed = discord.Embed(
title="📋 Utilisation de la commande",
description="**Syntaxe :** `!say #channel message`",
color=discord.Color.blue()
)
embed.add_field(name="Exemple", value="`!say #general Bonjour à tous !`", inline=False)
msg = await message.channel.send(embed=embed)
asyncio.create_task(delete_after_delay(msg))
return
if not message.channel_mentions:
embed = discord.Embed(
title="❌ Erreur",
description="Vous devez mentionner un canal avec #",
color=discord.Color.red()
)
msg = await message.channel.send(embed=embed)
asyncio.create_task(delete_after_delay(msg))
return
target_channel = message.channel_mentions[0]
text_to_send = parts[2]
try:
await target_channel.send(text_to_send)
await safe_delete_message(message)
except discord.Forbidden:
embed = discord.Embed(
title="❌ Erreur",
description="Je n'ai pas les permissions pour écrire dans ce canal.",
color=discord.Color.red()
)
msg = await message.channel.send(embed=embed)
asyncio.create_task(delete_after_delay(msg))
except Exception as e:
logging.error(f"Erreur lors de l'envoi du message: {e}")