Reputation: 17
I am currently getting a CommandNotFound error when trying to call the command inside of this class. The message listener function is also not responding.
ERROR discord.ext.commands.bot Ignoring exception in command None
discord.ext.commands.errors.CommandNotFound: Command "black" is not found
I can't seem to see what I am doing wrong here...
class MyCog(commands.Cog):
def __init__(self, bot):
self.bot = bot
@commands.Cog.listener()
async def on_message(self, message):
if message.content == "hello":
await message.channel.send("HI!")
@commands.command()
async def black(self, ctx):
await ctx.send("White!")
bot.add_cog(MyCog(bot))
bot.run(BOT_TOKEN)
Upvotes: 1
Views: 1598
Reputation: 1893
When you add a cog you need to await it.
await bot.add_cog(MyCog(bot))
To do that you'll need to change how you run your bot:
async def main():
async with bot:
await bot.add_cog(MyCog(bot))
await bot.start(BOT_TOKEN)
asyncio.run(main())
On another note, I would advise moving cogs into their own python file & directory. They're quite useful for organisation, but that is mostly lost when kept inside the main bot file.
Upvotes: 2