Refactor connect_voice_chan method to streamline voice channel connection logic
This commit is contained in:
parent
f4a16f88a9
commit
b2c1996b64
1 changed files with 5 additions and 4 deletions
|
@ -126,11 +126,12 @@ class VoiceBot:
|
|||
async def connect_voice_chan(
|
||||
self, channel: discord.VoiceChannel | discord.StageChannel
|
||||
) -> discord.VoiceClient:
|
||||
if channel.guild.id in self.vo:
|
||||
vo = self.vo.get(channel.guild.id, None)
|
||||
if vo is not None and vo.channel != channel:
|
||||
await self.disconnect_voice(channel.guild)
|
||||
|
||||
vo: discord.VoiceClient = await channel.connect()
|
||||
self.vo[channel.guild.id] = vo
|
||||
if vo is None or vo.channel != channel:
|
||||
vo = await channel.connect()
|
||||
self.vo[channel.guild.id] = vo
|
||||
return vo
|
||||
|
||||
async def disconnect_voice(self, guild: discord.Guild) -> None:
|
||||
|
|
Loading…
Add table
Reference in a new issue