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)