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])