Исправление ошибок с event
All checks were successful
CI / basic-checks (push) Successful in 11s

This commit is contained in:
2025-12-08 18:36:25 +07:00
parent 869dd545b7
commit 635a8c0f74
2 changed files with 17 additions and 19 deletions

View File

@@ -23,17 +23,14 @@ class Bot(commands.Bot):
intents: Optional[Intents] = None, intents: Optional[Intents] = None,
help_command: Optional[commands.HelpCommand] = None, help_command: Optional[commands.HelpCommand] = None,
) -> None: ) -> None:
# Intents по умолчанию
if intents is None: if intents is None:
intents = Intents.default() intents = Intents.default()
intents.guilds = True intents.guilds = True
intents.message_content = True # Требует включения в Developer Portal intents.message_content = True
intents.members = True intents.members = True
# Префикс по умолчанию
command_prefix: str = prefix or getattr(settings, "PREFIX", "!") command_prefix: str = prefix or getattr(settings, "PREFIX", "!")
# Help-команда по умолчанию
if help_command is None: if help_command is None:
help_command = MyHelpCommand() help_command = MyHelpCommand()
@@ -94,6 +91,20 @@ class Bot(commands.Bot):
logger.info(text="Запуск бота...", log_type="START") logger.info(text="Запуск бота...", log_type="START")
await self.start(use_token) 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( discbot: Bot = Bot(
token=settings.BOT_TOKEN, token=settings.BOT_TOKEN,

View File

@@ -61,9 +61,8 @@ class Events(Cog):
@Cog.listener() @Cog.listener()
async def on_message(self, message: discord.Message) -> None: async def on_message(self, message: discord.Message) -> None:
""" """
Событие получения сообщения. Проверяет чёрный список слов. Событие получения сообщения. Проверяет чёрный список слов
и передаёт сообщение обработчику команд.
:param message: Полученное сообщение.
""" """
if message.author.bot or not message.content: if message.author.bot or not message.content:
return return
@@ -94,20 +93,8 @@ class Events(Cog):
) )
return return
# Обработка команд ОБЯЗАТЕЛЬНО в конце, иначе команды не будут работать
await self.bot.process_commands(message) 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() @Cog.listener()
async def on_command_error(self, ctx: Context, error: CommandError) -> None: async def on_command_error(self, ctx: Context, error: CommandError) -> None:
""" """