Ask coding questions

← Back to all posts
need helpp

Does anyone know what I'm doing wrong? it's a command in python I'm doing for discord please i need help!! cod: @client.command()
async def Youtube(ctx, *, search):
query_string = urllib.parse.urlencode({
'search_query': search
htm_content = urllib.request.urlopen(
''+ query_string
search_results = re.findall('href=\"\?watch\?v=(.{11})',
await ctx.send(f'' + search_results[0])

InvisibleOne (3264)

change the first line to async def Youtube(ctx, search): you don't need the * just enclose the search in quotes if it is more then one word. * will return everything as a tuple or list I think

Coder100 (19280)

also send repl as well thank you


@Coder100 Ignoring exception in command Youtube:
Traceback (most recent call last):
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/ext/commands/", line 85, in wrapped
ret = await coro(*args, **kwargs)
File "", line 100, in Youtube
await ctx.send(f'' + search_results[0])
IndexError: list index out of range

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/ext/commands/", line 939, in invoke
await ctx.command.invoke(ctx)
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/ext/commands/", line 863, in invoke
await injected(*ctx.args, **ctx.kwargs)
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/ext/commands/", line 94, in wrapped
raise CommandInvokeError(exc) from exc
discord.ext.commands.errors.CommandInvokeError: Command raised an exception: IndexError: list index out of range

Coder100 (19280)

that meant there were no search results, search_results was [] @CAUESPINDOLA