Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Discord bot issue "is a required argument missing" python

I have a problem. I think this code is well written and the bot turns on and everything, but when I go to execute the commad play I get an error.

@bot.command(name='play', aliases=['sing','p'], description="streams music")
async def play_(ctx, self, *, search: str):
    #async def play_(ctx, message, self, *, search: str):
    """Request a song and add it to the queue.
    This command attempts to join a valid voice channel if the bot is not already in one.
    Uses YTDL to automatically search and retrieve a song.
    Parameters
    ------------
    search: str [Required]
        The song to search and retrieve using YTDL. This could be a simple search, an ID or URL.
    """
    await ctx.trigger_typing()

    vc = ctx.voice_client

    if not vc:
        await ctx.invoke(self.connect_)

    player = self.get_player(ctx)

    # If download is False, source will be a dict which will be used later to regather the stream.
    # If download is True, source will be a discord.FFmpegPCMAudio with a VolumeTransformer.
    source = await YTDLSource.create_source(ctx, search, loop=self.bot.loop, download=False)

    await player.queue.put(source)

The error is as follows:

    discord.ext.commands.errors.MissingRequiredArgument: search is a required argument that is missing.

And I don't know what to do because I have already tried to change the position but an error keeps coming out if someone knows what it is, please tell me

like image 514
Faliin Avatar asked Jul 11 '26 21:07

Faliin


1 Answers

Whatever your search parameter is for, it wont work. When the discord.py library calls a command, it calls the command as follows:

command(context, word1, word2, word3)

So if it would call your function, the named error would apper, because discord never passes a search argument to your function. E.g:

@bot.command(name='play', aliases=['sing','p'], description="streams music")
async def play_(ctx, self, *, search: str):
    [...]

-play see you again

play_(context, "see", "you", "again")

-> Error: search is a required argument that is missing


Instead, your function should look like the following:

@bot.command(name='play', aliases=['sing','p'], description="streams music")
async def play_(ctx, *search):
    [...]
like image 185
Thörni Avatar answered Jul 13 '26 13:07

Thörni



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!