Discord bot Python - CommandNotFound exception when using commands

I’m having trouble with my Discord music bot in Python

I created a Discord bot following some online guides but I keep getting this error whenever I try to use any command:

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

The bot appears online in my server and I’ve granted it all necessary permissions. I’ve reviewed my code multiple times but can’t identify what’s causing this issue. Any help would be greatly appreciated!

Here’s my code structure:

bot.py

import discord
from discord.ext import commands
import os

from utilities_cog import utilities_cog
from audio_cog import audio_cog

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

client.remove_command("help")

client.add_cog(utilities_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.paused_state = False
        self.song_queue = []
        self.YOUTUBE_OPTIONS = {"format": "bestaudio", "postprocessors": [{"key": "FFmpegExtractAudio", "preferredcodec": "mp3", "preferredquality": "192"}]}
        self.FFMPEG_SETTINGS = {"before_options": "-reconnect 1 -reconnect_streamed 1 -reconnect_delay_max 5", "options": "-vn"}
        self.voice_client = None

    def find_song(self, search_term):
        with YoutubeDL(self.YOUTUBE_OPTIONS) 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", "run"], help="Start playing music from YouTube")
    async def start(self, ctx, *arguments):
        search_query = " ".join(arguments)
        user_voice = ctx.author.voice.channel
        
        if user_voice 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_queue.append([track, user_voice])

    @commands.command(name="stop", help="Stop current playback")
    async def stop(self, ctx, *arguments):
        if self.currently_playing:
            self.currently_playing = False
            self.paused_state = True
            self.voice_client.pause()

utilities_cog.py

import discord
from discord.ext import commands

class utilities_cog(commands.Cog):
    def __init__(self, client):
        self.client = client
        self.help_text = "Available commands listed here"

    @commands.command(name="help", help="Show available commands")
    async def help(self, ctx):
        await ctx.send(self.help_text)

I had this same problem when I started making Discord bots. You’re probably adding cogs wrong. Discord.py deprecated add_cog in newer versions.

You could switch to await client.add_cog() but that needs an async setup function. Easier fix: use client.load_extension() instead and add a setup function to each cog file.

Add this to both cog files:

def setup(client):
    client.add_cog(audio_cog(client))

Then change your bot.py to:

client.load_extension('audio_cog')
client.load_extension('utilities_cog')

That’ll fix your CommandNotFound error.

check ur discord.py version first - there’s a cog loading bug in some versions. Either downgrade to 1.7.3 or upgrade to the latest 2.x. also double-check that your bot token has the right scopes in the discord developer portal.

Discord bot management is a pain. Skip the headache of manually registering commands - just automate everything.

I set up a system that handles command registration, error handling, and monitoring automatically. It watches for code changes, reloads cogs, manages tokens, and tracks uptime.

No more CommandNotFound errors since commands always register properly. You can easily add message scheduling and user management too.

Here’s how to build an automated Discord bot management system: https://latenode.com

Your cog initialization method is outdated - that’s the problem. I hit this same issue migrating an older bot. Your cogs look fine, but they’re not loading into the bot properly. The sync add_cog() method you’re using got deprecated. You need async loading or extension loading instead. Since your cogs are already structured right, just convert to async loading:

async def main():
    async with client:
        await client.add_cog(utilities_cog(client))
        await client.add_cog(audio_cog(client))
        await client.start(os.getenv("BOT_TOKEN"))

import asyncio
asyncio.run(main())

Ditch the sync client.run() call at the bottom. This registers your commands before the bot connects to Discord.