Reputation: 33
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
Upvotes: 3
Views: 508
Reputation: 555
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):
[...]
Upvotes: 1
Reputation: 61
Why do you have self
as a parameter? If you're in a cog, put it before ctx
. If you're not, remove that parameter. Your search term is being passed as the self
parameter.
Upvotes: 0