From 635a8c0f74edc7b7f5ed4a59c99b8370620ae31e Mon Sep 17 00:00:00 2001 From: Whyverum Date: Mon, 8 Dec 2025 18:36:25 +0700 Subject: [PATCH] =?UTF-8?q?=D0=98=D1=81=D0=BF=D1=80=D0=B0=D0=B2=D0=BB?= =?UTF-8?q?=D0=B5=D0=BD=D0=B8=D0=B5=20=D0=BE=D1=88=D0=B8=D0=B1=D0=BE=D0=BA?= =?UTF-8?q?=20=D1=81=20event?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bot/bot.py | 19 +++++++++++++++---- bot/cogs/events.py | 17 ++--------------- 2 files changed, 17 insertions(+), 19 deletions(-) diff --git a/bot/bot.py b/bot/bot.py index e3562f5..66e6c01 100644 --- a/bot/bot.py +++ b/bot/bot.py @@ -23,17 +23,14 @@ class Bot(commands.Bot): intents: Optional[Intents] = None, help_command: Optional[commands.HelpCommand] = None, ) -> None: - # Intents по умолчанию if intents is None: intents = Intents.default() intents.guilds = True - intents.message_content = True # Требует включения в Developer Portal + intents.message_content = True intents.members = True - # Префикс по умолчанию command_prefix: str = prefix or getattr(settings, "PREFIX", "!") - # Help-команда по умолчанию if help_command is None: help_command = MyHelpCommand() @@ -94,6 +91,20 @@ class Bot(commands.Bot): logger.info(text="Запуск бота...", log_type="START") await self.start(use_token) + @staticmethod + async def on_command(ctx: commands.Context) -> None: + """ + Глобальное логирование всех вызванных команд. + """ + logger.info( + text=( + f"Команда: {ctx.command} | Автор: {ctx.author} | " + f"Гильдия: {ctx.guild} | Сообщение: {ctx.message.content}" + ), + log_type="COMMAND", + user=str(ctx.author), + ) + discbot: Bot = Bot( token=settings.BOT_TOKEN, diff --git a/bot/cogs/events.py b/bot/cogs/events.py index 410d2a3..775036a 100644 --- a/bot/cogs/events.py +++ b/bot/cogs/events.py @@ -61,9 +61,8 @@ class Events(Cog): @Cog.listener() async def on_message(self, message: discord.Message) -> None: """ - Событие получения сообщения. Проверяет чёрный список слов. - - :param message: Полученное сообщение. + Событие получения сообщения. Проверяет чёрный список слов + и передаёт сообщение обработчику команд. """ if message.author.bot or not message.content: return @@ -94,20 +93,8 @@ class Events(Cog): ) return - # Обработка команд ОБЯЗАТЕЛЬНО в конце, иначе команды не будут работать await self.bot.process_commands(message) - @Cog.listener() - async def on_command(self, ctx: Context) -> None: - """ - Логирование всех вызванных команд. - """ - logger.info( - text=f"Команда: {ctx.command} | Автор: {ctx.author} | Гильдия: {ctx.guild} | Сообщение: {ctx.message.content}", - log_type="COMMAND", - user=str(ctx.author), - ) - @Cog.listener() async def on_command_error(self, ctx: Context, error: CommandError) -> None: """