Skip to content

Commit

Permalink
Try to explicitly clear own channel in force disconnect.
Browse files Browse the repository at this point in the history
  • Loading branch information
Ev-1 committed Jul 3, 2024
1 parent 71ebe80 commit 4b897c3
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 5 deletions.
9 changes: 8 additions & 1 deletion musicbot/cogs/music/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -559,11 +559,18 @@ async def _forcedisconnect(self, ctx):
try:
player = self.get_player(ctx.guild)
player.queue.clear()
# Hopefully helps
player.channel_id = None
await player.stop()
except Exception as e:
self.logger.error("Error forcedisconnecting")
self.logger.exception(e)
await ctx.voice_client.disconnect(force=True)

if ctx.voice_client:
await ctx.voice_client.disconnect(force=True)
else:
self.logger.error("Voice client no longer exists")

embed = discord.Embed(description='{disconnect.disconnected}', color=ctx.me.color)
embed = ctx.localizer.format_embed(embed)
await ctx.send(embed=embed)
Expand Down
15 changes: 12 additions & 3 deletions musicbot/cogs/music/decorators.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import asyncio
import functools
import inspect
import logging
import math

import discord
Expand All @@ -11,6 +12,8 @@
from . import music_errors
from .voice_client import BasicVoiceClient

logger = logging.getLogger("musicbot").getChild("decorators")


def require_voice_connection(should_connect=False):
"""Checks if the bot is in a valid voice channel for the command
Expand Down Expand Up @@ -50,9 +53,15 @@ async def ensure_voice_inner(self, ctx, *command_args, **kwargs):
await ctx.author.voice.channel.connect(cls=BasicVoiceClient)

elif player.channel_id and int(player.channel_id) != ctx.author.voice.channel.id:
bot_channel = self.bot.get_channel(int(player.channel_id))
raise music_errors.UserInDifferentVoiceChannelError('You need to be in my voice channel',
channel=bot_channel)
if ctx.voice_client:
bot_channel = self.bot.get_channel(int(player.channel_id))
raise music_errors.UserInDifferentVoiceChannelError('You need to be in my voice channel',
channel=bot_channel)
else:
# We are not connected anymore
logger.debug("Voice client no longer exists, clear voice state")
player.channel_id = None
player._voice_state.clear()

await func(self, ctx, *command_args, **kwargs)

Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
discord.py == 2.3.*
lavalink == 5.3.*
lavalink == 5.5.*
asyncio
pyyaml
BeautifulSoup4
Expand Down

0 comments on commit 4b897c3

Please sign in to comment.