Skip to content

[BUG] Bot fails to disconnect properly from voice channel when used across multiple guilds #1531

Closed
@tequa

Description

@tequa

Library Version

5.9.2

Describe the Bug

The connect and disconnect voice channel endpoints for my bot work just fine when using in a single guild. But when I use the bot in multiple guilds, if I disconnect from a voice channel in 1 guild, and then subsequently disconnect from a voice channel in another guild, the second bot will seemingly disconnect from the voice channel but its voice state will not update. Because its voice state fails to be set to null, it will fail to further connect to the same voice channel because it thinks it's still connected to it.

Steps to Reproduce

  1. Set up the endpoints in the code pasted below
  2. In 2 different guilds with 2 different accounts, join a voice channel
  3. Call /join_voice in each guild. Each bot should successfully join the voice channel.
  4. Call /leave voice in bot 1's guild; they should successfully leave the voice channel and this INFO message will show:
    2023-08-15 07:07:47 | INFO | interactions | Disconnecting from voice channel ###
  5. Call /leave_voice in bot 2's guild. The bot will leave the voice channel BUT there will be no INFO message for the disconnect.
  6. Call /join_voice in bot 2's guild. They will fail to join because their voice state is non-null and the bot still thinks it's in the voice channel

I originally got the bug on a messy Python 3.10 project but was able to reproduce it again with a fresh Python 3.11 virtual env after doing just pip install discord-py-interactions and pip install discord.py-interactions[voice] and using the code below

Expected Results

Connecting and disconnecting from the channels across guilds should not interfere with one another.

Minimal Reproducible Code

@interactions.slash_command(
    name="join_voice",
    description="Connect and stay in the voice channel you're currently in",
)
async def join_voice(ctx: SlashContext):
    if not ctx.author.voice:
        await ctx.send("You are not in a voice channel", ephemeral=True)
        return
    channel = ctx.author.voice.channel
    await channel.connect()

    await ctx.send("Joining voice channel!")


@interactions.slash_command(
    name="leave_voice",
    description="Kick the bot from the voice channel its currently in",
)
async def leave_voice(ctx: SlashContext):
    voice_state = ctx.voice_state
    if not voice_state:
        await ctx.send("The bot is not in any voice channel!", ephemeral=True)
        return
    await voice_state.channel.disconnect()
    
    await ctx.send("Leaving voice channel!") 
    
bot = interactions.Client(token=discord_bot_key, intents=interactions.Intents.DEFAULT)
bot.start()

Traceback

No relevant traceback

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.
  • I have attempted to debug this myself, and I believe this issue is with the library

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions