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,
|
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,
|
||||||
|
|||||||
@@ -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:
|
||||||
"""
|
"""
|
||||||
|
|||||||
Reference in New Issue
Block a user