From 8d346943da080eed7b22ca2ce8373030a349adf9 Mon Sep 17 00:00:00 2001 From: deadzilla Date: Thu, 9 Jul 2026 10:17:33 +0500 Subject: [PATCH] =?UTF-8?q?=D0=97=D0=B0=D0=BC=D0=B5=D0=BD=D0=B0=20embed-?= =?UTF-8?q?=D0=B2=D1=8B=D0=B2=D0=BE=D0=B4=D0=B0=20!help=20=D0=BD=D0=B0=20?= =?UTF-8?q?=D0=BF=D1=80=D0=BE=D1=81=D1=82=D0=BE=D0=B9=20=D1=82=D0=B5=D0=BA?= =?UTF-8?q?=D1=81=D1=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bot.py | 68 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 67 insertions(+), 1 deletion(-) diff --git a/bot.py b/bot.py index e52d3a0..fd51c3d 100644 --- a/bot.py +++ b/bot.py @@ -24,6 +24,68 @@ if TYPE_CHECKING: logger = logging.getLogger(__name__) + +class TextHelpCommand(commands.HelpCommand): + """Выводит справку по командам простым текстом вместо embed.""" + + def get_command_signature(self, command: commands.Command) -> str: + return f"!{command.qualified_name} {command.signature}" + + async def send_bot_help( + self, mapping: dict[discord.ext.commands.Command, list[discord.ext.commands.Command]] + ) -> None: + lines: list[str] = ["Доступные команды:"] + + for cog_or_none, cog_commands in mapping.items(): + if cog_or_none is None: + # Команды без cog (встроенная help) — пропускаем + continue + for command in cog_commands: + if not command.hidden: + desc = command.short_doc or "" + lines.append(f" !{command.name} - {desc}") + + lines.append("\nВведите !<название команды> для использования.") + await self.get_destination().send("\n".join(lines)) + + async def send_cog_help( + self, cog: discord.ext.commands.Cog + ) -> None: + commands_with_desc = cog.get_commands() + lines: list[str] = [f"Команды [{cog.qualified_name}]:"] + for command in commands_with_desc: + if not command.hidden: + desc = command.short_doc or "" + lines.append(f" !{command.name} - {desc}") + + await self.get_destination().send("\n".join(lines)) + + async def send_command_help(self, command: commands.Command) -> None: + lines: list[str] = [f"!{command.qualified_name} {command.signature}"] + if command.doc: + lines.append(command.short_doc or command.help) + if command.aliases: + lines.append(f"\nАлиасы: {', '.join('!' + a for a in command.aliases)}") + + await self.get_destination().send("\n".join(lines)) + + async def send_group_help( + self, group: commands.Group + ) -> None: + lines: list[str] = [f"!{group.qualified_name} {group.signature}"] + if group.doc: + lines.append(group.short_doc or group.help) + + for command in group.commands: + if not command.hidden: + desc = command.short_doc or "" + lines.append(f" !{command.name} - {desc}") + + await self.get_destination().send("\n".join(lines)) + + async def send_error_message(self, error: str) -> None: + await self.get_destination().send(error) + load_dotenv() intents = discord.Intents.default() @@ -34,7 +96,11 @@ class BotRunner: """Управляет жизненным циклом бота.""" def __init__(self) -> None: - self.bot = commands.Bot(command_prefix="!", intents=intents) + self.bot = commands.Bot( + command_prefix="!", + intents=intents, + help_command=TextHelpCommand(), + ) self.bot._start_time = time.time() self.stop_event = threading.Event() self.bot_ready = threading.Event()