1

I'm trying to create a music bot for discord and I finish the code and tried to run it and when I run the play command it simply says this.

Ignoring exception in command None:
discord.ext.commands.errors.CommandNotFound: Command "play" is not found

Here's my code.

import discord
from discord.ext import commands
import youtube_dl

TOKEN = "Token here"
bot = discord.ext.commands.Bot(command_prefix = "s ");

@bot.event
    async def on_ready():
    channel = discord.utils.get(bot.get_all_channels(), id=794444804607574026)
    await channel.connect()

 async def play(ctx, url):
     player = await voice_client.create_ytdl_player(url)
     player.start()

 bot.run(TOKEN) 
Superior125
  • 55
  • 3
  • 9

3 Answers3

1

You haven't added @bot.command(name="play") above the play function

import discord
from discord.ext import commands
import youtube_dl

TOKEN = "Token here"
bot = discord.ext.commands.Bot(command_prefix = "s ");

@bot.event
async def on_ready():
    channel = discord.utils.get(bot.get_all_channels(), id=794444804607574026)
    await channel.connect()
 
 @bot.command(name="play")
 async def play(ctx, url):
     player = await voice_client.create_ytdl_player(url)
     player.start()

 bot.run(TOKEN) 
0

before

async def play(ctx, url):
    player = await voice_client.create_ytdl_player(url)
    player.start()

after

@bot.command()
async def play(ctx, url):
    player = await voice_client.create_ytdl_player(url)
    player.start()
0

Simply use this code:

main.py

from discord.ext import commands
from discord.ext.commands import bot

import discord
import os
import youtube_dl

bot = commands.Bot(command_prefix="s")

@bot.event
async def on_ready()
    print("{0.user} is online".format(bot))

@bot.command()
async def play(ctx, url):
    player = await voice_client.create_ytdl_player(url)
    player.start()

.env

TOKEN=<paste your token here>

Hope it’s helped you (: