This commit is contained in:
19
bot/bot.py
19
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,
|
||||
|
||||
@@ -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:
|
||||
"""
|
||||
|
||||
Reference in New Issue
Block a user