#The bot does not see the command from Cog

1 messages · Page 1 of 1 (latest)

torpid galleon
#

For some reason my bot does not see the command, although it is registered by the decorator

from loguru import logger

logger.add('debug.json',
           format='{time:YYYY-MM-DD at HH:mm:ss} | {level} | {message}',
           level='DEBUG',
           rotation='250MB',
           compression='zip',
           serialize=True)

import disnake
from disnake.ext import commands
from config import settings
from cogs.commands.info import InfoCommand

INTENTS = disnake.Intents.all()

class TeamBot(commands.Bot):
    @logger.catch
    def __init__(self):
        super().__init__(intents=INTENTS,
                    reload=True,
                    help_command=None,
                    command_prefix=settings.PREFIX_COMMAND_BOT,
                    command_sync_flags=commands.CommandSyncFlags.all())

if __name__ == "__main__":
    bot = TeamBot()

    bot.add_cog(InfoCommand(bot))

    bot.run(settings.TOKEN_BOT)
import disnake
from disnake.ext import commands
from loguru import logger


class InfoCommand(commands.Cog):
    def __init__(self, bot):
        self._bot = bot
        logger.info(f'Cog "{__name__}" loaded.')

    @logger.catch
    @commands.command(name="info", description="Get info about a command.")
    async def info(self, ctx):
        await ctx.send('info')
Ignoring exception in command None:
disnake.ext.commands.errors.CommandNotFound: Command "info" is not found

novel pikeBOT
#

Hey @torpid galleon!

It looks like you incorrectly specified a language for your code block.

Make sure you put your code on a new line following py. There must not be any spaces after py.

Here is an example of how it should look:
```py
print('Hello, world!')
```

This will result in the following:

print('Hello, world!')```
You can **edit your original message** to correct your code block.
uncut skiff
#

have you defined it?

torpid galleon
#

Why do I need to configure a function if I immediately add a cog when I turn on the bot?

    bot.add_cog(InfoCommand(bot))

Or are you talking about something else? Can you give me an example?

uncut skiff
#

no wait nvm you are importing the cog

#

it should be working

#

do you have an on_message event listener somewhere?

torpid galleon
#

Yes


import random
import disnake
from disnake import PartialEmoji
from disnake.ext import commands
from loguru import logger

class OnMessage(commands.Cog):
    def __init__(self, bot):
        self._bot = bot
        logger.info(f'Cog "{__name__}" loaded.')

    def try_reaction_message(self, max_digit: int = 20) -> bool:
        min_digit: int = 0

        rand: int = random.randint(min_digit, max_digit)
        if rand == min_digit:
            return True

        return False

    @logger.catch
    @commands.Cog.listener()
    @commands.guild_only()
    async def on_message(self, message: disnake.Message):
        if message.author.bot:
            return False

        if message.guild is None:
            return False

        if self.try_reaction_message():
            await message.add_reaction(emoji='❤️')
            logger.info(f'Reacted heart "{message.author}" to "{message.content}"')





uncut skiff
#

that shouldn't be an issue

#

I know this may seem a stupid question, but did you save your files and restart your Bot?

torpid galleon
#

Yes, I've been trying to figure this out for about three hours now, but I can't find the answer)

#

During this time I have already restarted the PC twice

uncut skiff
#

any reason why you aren't using extensions?

torpid galleon
#

I couldn’t figure it out because the cogs were scattered in folders and I found such an implementation in one git repository.

torpid galleon
#

@uncut skiff have a suggestion?

floral pine
#

Does it log that the Cog was loaded

#

I think I know the issue

#

Remove @logger.catch, or move it below @commands.command

#

Though moving it below may cause other issues

#

@torpid galleon

torpid galleon
#

How funny and at the same time sad, really the whole problem is in logging. Thanks a lot for your help