2

So, I'm creating a music bot that play musics when a user specify a Youtube URL, here's the code:

@commands.command() # I'm creating this command in a cog by the way
async def play(self, ctx, url: str):
    # Stop the current track if a song was playing.
    ctx.voice_client.stop()
    
    # Just some stuff that help the bot play the specified song
    FFMPEG_OPTIONS = {
        "before_options": "-reconnect 1 -reconnect_streamed 1 -reconnect_delay_max 5",
            "options": "-vn"
    }

    YDL_OPTIONS = {"formats": "bestaudio"}
    vc = ctx.voice_client

    with youtube_dl.YoutubeDL(YDL_OPTIONS) as ydl:
        info = ydl.extract_info(url, download=False)
        url2 = info["formats"][0]["url"]
        src = await discord.FFmpegOpusAudio.from_probe(url2, **FFMPEG_OPTIONS)

        vc.play(src)

Realizing that my command needs an error handler to check whether the user entered a URL as an argument for the command, if not then send an error message.

@play.error
async def play_error_handler(self, ctx, error):
    if isinstance(error, commands.MissingRequiredArgument):
        await ctx.send("Please pass in a url in order to play a song.")

But then when I tested it, it didn't show me any messages neither on the console nor on the chat; another weird part of this is when I test other commands like ping command or so, it caused the same problem as above. The only thing that worked is the client mention event, basically what it does is it sends a message about the bot's prefix to the user when someone mentions it:

@client.event # this event is located on the main file
async def on_message(message):
    if client.user.mentioned_in(message):
        await message.channel.send(f'My prefix here is `.`')

I tried re-giving it permissions and regenerate the token but neither of them worked. I checked the error handler syntax on this Youtube tutorial and I don't see any problems going on with it (maybe).

Why is this happening? Did I missed something important perhaps?

1 Answers1

0

After testing for a while, I realized that my client's mention event is overriding other commands. So I decided to remove it and it worked like normal.

for more information, please check: Why does on_message stop commands from working?