Home > OS >  Whenever a user sends a message in my music bot, it only takes the first word. I want it to take the
Whenever a user sends a message in my music bot, it only takes the first word. I want it to take the

Time:10-02

Whenever I type a message, such as ".play never gonna give you up", my code only takes in the first word after ".play", that would be "never". I need to fix this but I have no idea

@client.command()
async def play(ctx, url):
    search_keyword = add(url)
    print(url)
    html = urllib.request.urlopen("https://www.youtube.com/results?search_query="   search_keyword)
    video_ids = re.findall(r"watch\?v=(\S{11})", html.read().decode())
    link = "https://www.youtube.com/watch?v="   video_ids[0]
    print(link)
    YDL_OPTIONS = {'format': 'bestaudio', 'noplaylist': 'True'}
    FFMPEG_OPTIONS = {
        'before_options': '-reconnect 1 -reconnect_streamed 1 -reconnect_delay_max 5', 'options': '-vn'}
    voice = get(client.voice_clients, guild=ctx.guild)

    if not voice.is_playing():
        with YoutubeDL(YDL_OPTIONS) as ydl:
            info = ydl.extract_info(link, download=False)
        URL = info['url']
        voice.play(FFmpegPCMAudio(URL, **FFMPEG_OPTIONS))
        voice.is_playing()

CodePudding user response:

Here you go, nice and simple. now all following inputs will be a part of the url variable.

async def play(ctx, *, url):
  • Related