[Python] "(" was not closed but it was? [closed]

Discussão em 'Python' iniciado por Stack, Julho 30, 2025.

  1. Stack

    Stack Membro Participativo

    i'm trying to make a music bot for discord but when i try to setup the source it keeps telling me to close a bracket on line 75, but it does appear closed to me. i don't understand what is the issue here ? i tried adding another bracket but that didn't help. what else can i try to resolve this issue ?

    import os
    import discord
    from discord.ext import commands
    from discord import app_commands
    from dotenv import load_dotenv
    import yt_dlp
    import asyncio

    load_dotenv()
    DISCORD_TOKEN = os.getenv("DISCORD_TOKEN")

    intents = discord.Intents.default()
    intents.message_content = True

    async def search_ytdlp_async(query, ydl_opts):
    loop = asyncio.get_running_loop()
    return await loop.run_in_executor(None, lambda: _extract(query, ydl_opts))

    def _extract(query, ydl_options):
    with yt_dlp.YoutubeDL(ydl_options) as ydl:
    return ydl.extract_info(query, download=False)

    bot = commands.Bot(command_prefix="%", intents=intents)

    @bot.event
    async def on_ready():
    await bot.tree.sync()
    print(f"{bot.user} is online!")


    #structure and definition of command
    @bot.tree.command(name="play", description="Play a song or add it to the queue.")
    @app_commands.describe(song_query="Search query")
    async def play(interaction: discord.Interaction, song_query: str):
    await interaction.response.defer()

    voice_channel = interaction.user.voice.channel

    if voice_channel is None:
    await interaction.followup.send("You musy be in a voive channel.")
    return

    # retrieve voice client of the bot
    voice_client = interaction.guild.voice_client

    if voice_client is None:
    voice_client = await voice_channel.connect()
    elif voice_channel != voice_client.channel:
    await voice_client.move_to(voice_channel)

    ydl_options = {
    "format": "bestaudio[abr<=96]/bestaudio",
    "noplaylist": True,
    "youtube_include_dash_manifest": False,
    "youtube_include_his_manifest": False
    }

    query = "ytsearch1" = song_query
    results = await search_ytdlp_async(query, ydl_options)
    tracks = results.get("entries", [])

    if tracks is None:
    await interaction.following.send("No results found.")
    return

    first_track = tracks[0]
    audio_url = first_track["url"]
    title = first_track.get("title", "untitled")

    ffmepeg_options = {
    "before_options": "-reconnect 1 -reconnect_streamed 1 - reconnect_delay_max 5",
    "options": "-vn -c:a libopus -b:a 96k",
    }

    source = discord.FFmepegOpusAudio(audio_url, **ffmepeg_options, executable=bin\\ffmpeg\\ffmpeg.exe)
    voice_client.play(source)

    bot.run(DISCORD_TOKEN)

    Continue reading...

Compartilhe esta Página