Не регистрируется комманда discord.py
Делаю дискорд бота для модерации и столкнулся с ошибкой. Создал файл с командами, написал первую команду, регистрирую её в main.py
, а на выводе получаю
[2024-07-24 13:24:25] [ERROR ] discord.ext.commands.bot: Ignoring exception in command None
discord.ext.commands.errors.CommandNotFound: Command "clear" is not found
Мой main.py:
import logging
import discord
from discord.ext import commands
from dotenv import load_dotenv
import os
from cogs import moderation
from Logging.MessageLogging import log_message, log_message_delete
from Logging.VoiceStateLogging import log_voice_state_update
from logging.handlers import RotatingFileHandler
load_dotenv()
TOKEN = os.getenv('BOT_TOKEN')
#Logging settings for text messages
message_logger = logging.getLogger('message_logger')
message_logger.setLevel(logging.INFO)
message_handler = RotatingFileHandler('logs/message_log.txt', maxBytes=10485760, backupCount=5, encoding='utf-8')
message_formatter = logging.Formatter('[%(asctime)s] [%(levelname)s] %(message)s', datefmt='%d-%m-%Y, %H:%M:%S')
message_handler.setFormatter(message_formatter)
message_logger.addHandler(message_handler)
#Logging setting for delete messages
delete_logger = logging.getLogger('delete_logger')
delete_logger.setLevel(logging.INFO)
delete_handler = RotatingFileHandler('logs/delete_message_log.txt', maxBytes=10485760, backupCount=5, encoding='utf-8')
delete_formatter = logging.Formatter('[%(asctime)s] [%(levelname)s] %(message)s', datefmt='%d-%m-%Y, %H:%M:%S')
delete_handler.setFormatter(message_formatter)
delete_logger.addHandler(message_handler)
#Logging settings for voice
voice_logger = logging.getLogger('voice_logger')
voice_logger.setLevel(logging.INFO)
voice_handler = RotatingFileHandler('logs/voice_log.txt', maxBytes=10485760, backupCount=5, encoding='utf-8')
voice_formatter = logging.Formatter('[%(asctime)s] [%(levelname)s] %(message)s', datefmt='%d-%m-%Y, %H:%M:%S')
voice_handler.setFormatter(voice_formatter)
voice_logger.addHandler(voice_handler)
intents = discord.Intents.default()
intents.message_content = True
intents.messages = True
intents.guilds = True
intents.voice_states = True
bot = commands.Bot(command_prefix="/", intents=intents)
async def load_extensions():
await bot.load_extension('cogs.LogCommand')
#Status checker
@bot.event
async def on_ready():
message_logger.info('Bot is ready')
#Message logger
@bot.event
async def on_message(message):
log_message(message)
await bot.process_commands(message)
#Message delete logger
@bot.event
async def on_message_delete(message):
log_message_delete(message)
#Voice logger
@bot.event
async def on_voice_state_update(member, before, after):
log_voice_state_update(member, before, after)
#Регистрация команды
async def clear():
await bot.add_cog(moderation(bot))
bot.run(TOKEN)
Файл moderation.py:
import discord
from discord.ext import commands
class Moderation(commands.Cog):
def __init__(self, bot):
self.bot = bot
@commands.command()
async def clear(self, ctx, amount: int):
messages = await ctx.channel.purge(limit=amount + 1)
await ctx.reply(f'{len(messages)} было ощищено')
def setup(bot):
bot.add_cog(Moderation(bot = bot))
Заранее спасибо.