Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

It takes a minute for the client to disconnect from voice channel, if bot is forcefully disconnected from voice channel. #9575

Closed
3 tasks done
Haiz14 opened this issue Sep 22, 2023 · 6 comments · Fixed by #9525
Labels
unconfirmed bug A bug report that needs triaging

Comments

@Haiz14
Copy link

Haiz14 commented Sep 22, 2023

Summary

The bot tried to reconnect to a voice channel for a minute before disconnecting from voice channel, if the bot is forcefully disconnected.

Reproduction Steps

  • connect to a voice channel
  • disconnect bot manually by clicking on disconnect button in bot's profile
  • try to reconnect under 60 secs, via voice_channel.connect() you'll get error Error: Already connected to voice channel.
  • After 60-65 secs you can connect and there won't be any error.
    The logger shows
2023-09-22 10:24:04 INFO     discord.voice_client Disconnected from voice by force... potentially reconnecting.
2023-09-22 10:24:04 INFO     discord.voice_client Starting voice handshake... (connection attempt 2)
2023-09-22 10:25:04 INFO     discord.voice_client The voice handshake is being terminated for Channel ID 1153582285950558240 (Guild ID 1059338776146612254)
2023-09-22 10:25:04 INFO     discord.voice_client Reconnect was unsuccessful, disconnecting from voice normally...

disconnect button (Bot is forcefully disconnected via this button)

Minimal Reproducible Code

import discord
from discord.ext.commands import Bot

VOICE_CHANNEL_ID = ""
TOKEN = ""

PREFIX = "!"
DEVELOPER_INFO_MESSAGE = "If this error repeats, please snap a pic of this message and send it to the developer. They'll be happy to help you get back on track!"

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

bot = Bot(command_prefix=list(PREFIX), intents=intents) 


@bot.event
async def on_ready():
    #await add_help_command_with_embed(bot)
    bot.player = await setup_player(bot)

    print('Music Bot Ready')


async def setup_player(bot):
    voice_channel = await bot.fetch_channel(VOICE_CHANNEL_ID)
    player = await voice_channel.connect()

    return player


@bot.command(aliases=['r'])
async def reset(ctx):
    """
 Give the radio a good ol' reset! Use this command if the radio isn't working for some reason.
    """

    try:

        ctx.bot.player = await setup_player(ctx.bot)
        await ctx.send("Bot reconnected")
    except Exception as e:
        await ctx.send("Error: " +  str(e))

bot.run(TOKEN)

Expected Results

  • Fill in voice channel id and bot token
  • run the code
  • manually disconnect the bot
  • run !r command, and the bot should reconnect

Actual Results

The bot doesn't reconnect for 60-65 secs, after that it reconnect normally.

Intents

message_content, voice_states

System Information

❯ python -m discord -v

Checklist

  • I have searched the open issues for duplicates.
  • I have shown the entire traceback, if possible.
  • I have removed my token from display, if visible.

Additional Context

No response

@Haiz14 Haiz14 added the unconfirmed bug A bug report that needs triaging label Sep 22, 2023
@imayhaveborkedit
Copy link
Contributor

imayhaveborkedit commented Sep 22, 2023

This will be fixed with #9525, as far as ambiguity is concerned. The default timeout on connect is currently 60 seconds, but the underlying cause is still probably on your side.

@Haiz14
Copy link
Author

Haiz14 commented Sep 22, 2023

But why is it trying to reconnect for 60secs? If it's disconnected forcefully then disconnect.

@imayhaveborkedit
Copy link
Contributor

That's just how long the timeout is. If it's a weird state issue this pr might fix it.

@Haiz14
Copy link
Author

Haiz14 commented Sep 22, 2023

Yupp should be a weird state issue, Even if I try to disconnect and connect, after forcefully disconnecting the bot (via disconnect button), I still get Error: Already connected to a voice channel

import discord
from discord.ext.commands import Bot

VOICE_CHANNEL_ID = ""
TOKEN = ""

PREFIX = "!"
DEVELOPER_INFO_MESSAGE = "If this error repeats, please snap a pic of this message and send it to the developer. They'll be happy to help you get back on track!"

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

bot = Bot(command_prefix=list(PREFIX), intents=intents) 


@bot.event
async def on_ready():
    #await add_help_command_with_embed(bot)
    bot.player = await setup_player(bot)

    print('Music Bot Ready')


async def setup_player(bot, disconnect = False):
    if disconnect: await bot.player.disconnect()
    voice_channel = await bot.fetch_channel(VOICE_CHANNEL_ID)
    player = await voice_channel.connect()

    return player


@bot.command(aliases=['r'])
async def reset(ctx):
    """
 Give the radio a good ol' reset! Use this command if the radio isn't working for some reason.
    """

    try:

        ctx.bot.player = await setup_player(ctx.bot, True)
        await ctx.send("Bot reconnected")
    except Exception as e:
        await ctx.send("Error: " +  str(e))

bot.run(TOKEN)

@imayhaveborkedit
Copy link
Contributor

In that example you would want to use disconnect(force=True), but yeah the bot thinking it's connected when it isn't is one of the bugs fixed in that pr.

@Haiz14
Copy link
Author

Haiz14 commented Sep 22, 2023

When trying to reconnect to a forcefully disconnected channel:
First: disconnect(force = True)
Then connect() .


Thks, you are really great developer. You can actually make sense of the code in this short period of time. If you gave it to me, i would certainly be slower. Thks

@Haiz14 Haiz14 closed this as completed Sep 22, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
unconfirmed bug A bug report that needs triaging
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants