[Python] Bot gets "Unclosed connection" when joining a voice channel for the first time

Discussão em 'Python' iniciado por Stack, Setembro 7, 2025.

  1. Stack

    Stack Membro Participativo

    I am building a Discord bot using py-cord.
    When the bot tries to join a voice channel for the very first time in a server, I immediately get the following warning in the console:

    Unclosed connection
    client_connection: Connection<ConnectionKey(host='c-lax09-d2cb781f.discord.media', port=443, is_ssl=True, ssl=True, proxy=None, proxy_auth=None, proxy_headers_hash=None)>


    Things I have tried:

    • Check if the bot have enough permission
    • Calling disconnect(force=True) before connecting
    • Clearing voice states on startup
    • Restarting the bot and rejoining the same channel
    • Joining a different channel (Different channel is work, but it will raise same exception while I try on the original channel)

    Notes:

    • I only want the bot to connect to the voice channel (no audio playback yet).
    • Library: py-cord (latest version)
    • FFmpeg and PyNaCl are installed
    • The bot has Connect and Speak permissions

    My current code to clear voice client while startup:

    @bot.event
    async def on_ready():
    for vc in bot.voice_clients:
    await vc.disconnect(force=True)


    My current code to connect to the channel:

    ctx.author.voice.channel.connect(reconnect=True, timeout=10)

    Continue reading...

Compartilhe esta Página