Discord bot Python CommandNotFound exception issue

I’m experiencing an issue with my Discord bot created in Python. Each time I attempt to execute any command, I receive the following error message:

discord.ext.commands.errors.CommandNotFound: Command "start" is not found

Although the bot seems to be online on my server and has all the required permissions, I’ve gone through my code repeatedly and haven’t found any errors. I would really appreciate any assistance!

Here’s a look at my code setup:

bot.py

import discord
from discord.ext import commands
import os

from support_cog import support_cog
from audio_cog import audio_cog

client = commands.Bot(command_prefix="!", intents=discord.Intents.all())

client.remove_command("help")

client.add_cog(support_cog(client))
client.add_cog(audio_cog(client))

client.run(os.getenv("BOT_TOKEN"))

audio_cog.py

import discord
from discord.ext import commands
from yt_dlp import YoutubeDL
import yt_dlp as youtube_dl

class audio_cog(commands.Cog):
    def __init__(self, client):
        self.client = client
        self.currently_playing = False
        self.is_stopped = False
        self.song_list = []
        self.YDL_CONFIG = {"format": "bestaudio", "postprocessors": [{"key": "FFmpegExtractAudio", "preferredcodec": "mp3", "preferredquality": "192"}]}
        self.FFMPEG_CONFIG = {"before_options": "-reconnect 1 -reconnect_streamed 1 -reconnect_delay_max 5", "options": "-vn"}
        self.voice_client = None
        print("Audio module loaded")

    def find_song(self, search_term):
        with YoutubeDL(self.YDL_CONFIG) as downloader:
            try:
                result = downloader.extract_info(f"ytsearch:{search_term}", download=False)["entries"][0]
            except Exception:
                return False
        return {"source": result["url"], "title": result["title"]}

    @commands.command(name="start", aliases=["begin", "s"], help="Start playing audio from YouTube")
    async def start(self, ctx, *args):
        search_query = " ".join(args)
        user_channel = ctx.author.voice.channel
        if user_channel is None:
            await ctx.send("Please join a voice channel first!")
        else:
            track = self.find_song(search_query)
            if type(track) == type(True):
                await ctx.send("Unable to find that song. Try different keywords")
            else:
                await ctx.send("Track added to playlist")
                self.song_list.append([track, user_channel])

hmm looks like your cog setup might be the issue here. try using await client.add_cog() instead of just client.add_cog() - discord.py updated how cogs work and now requires async loading. also make sure you’re calling the commands with the right prefix!

The issue stems from how you’re instantiating your cog classes. In your bot.py file, you’re calling audio_cog(client) and support_cog(client) directly, but these should be class references without parentheses when using the older add_cog syntax. However, there’s a more fundamental problem - you’re mixing synchronous cog loading in an environment that expects asynchronous operations. I encountered this exact error when migrating an older bot to discord.py 2.0. The solution is to either use the new async setup pattern or ensure your cog classes are properly structured. Try changing your bot.py to load cogs after the bot is ready by using an on_ready event, or better yet, convert to the modern extension loading system. The CommandNotFound error occurs because the cogs aren’t actually being registered during the synchronous loading phase.

I noticed you’re using client.add_cog() which is actually deprecated in newer versions of discord.py. The correct approach is to use await client.load_extension() instead. You’ll need to restructure your code a bit though. Move your cog loading inside an async function and use client.setup_hook() or load them after the bot starts. Also, make sure your cog classes have an async def setup() function at the bottom of each cog file that does await bot.add_cog(YourCogClass(bot)). This synchronous vs asynchronous loading issue is probably why your commands aren’t being registered properly even though the bot appears online.