Skip to content

Commit

Permalink
🐛 Fix spammed no vc connection errors
Browse files Browse the repository at this point in the history
  • Loading branch information
transcental committed Jul 1, 2023
1 parent 5f12933 commit ed5ea1f
Showing 1 changed file with 27 additions and 32 deletions.
59 changes: 27 additions & 32 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,7 @@ async def play(interaction: Interaction):
voice_channel = voice.channel
if not voice_channel:
raise NoVCError()
await voice_channel.connect(reconnect=True)
voice_client = guild.voice_client
await voice_channel.connect(reconnect=True, self_deaf=True)

await interaction.response.send_message(
embed=await create_embed(
Expand All @@ -159,20 +158,21 @@ async def play(interaction: Interaction):

async def play_music():
while True:
voice_client = guild.voice_client

if not voice_channel:
raise NoVCError()

if type(voice_client) != discord.VoiceClient:
return await interaction.response.send_message(
return await voice_channel.send(
embed=await create_embed(
title="Error",
description="Could not get voice client",
)
)

if voice_channel != voice_client.channel:
break

if not voice_channel:
raise NoVCError()

server = server_collection.find_one({"id": guild.id})
if not server:
return await voice_channel.send(
Expand Down Expand Up @@ -272,33 +272,28 @@ async def stop(interaction: Interaction):

voice_client = guild.voice_client

if type(voice_client) != discord.VoiceClient:
return await interaction.response.send_message(
embed=await create_embed(
title="Error",
description="Could not get voice client",
)
)

if voice_client and voice_client.is_playing():
voice_client.stop()
await voice_client.disconnect()

return await interaction.response.send_message(
embed=await create_embed(
title="Music Stopped",
description="The music playback has been stopped.",
color=discord.Color.green(),
if (
type(voice_client) != discord.VoiceClient
or type(voice_client) != discord.VoiceProtocol
):
if voice_client:
await voice_client.disconnect(force=False)

return await interaction.response.send_message(
embed=await create_embed(
title="Music Stopped",
description="The music playback has been stopped.",
color=discord.Color.green(),
)
)
)
else:
return await interaction.response.send_message(
embed=await create_embed(
title="Not Playing",
description="There is no music currently playing.",
color=discord.Color.orange(),
else:
return await interaction.response.send_message(
embed=await create_embed(
title="Not in vc",
description="Couldn't disconnect as I'm not in vc silly",
color=discord.Color.orange(),
)
)
)


async def timezone_autocomplete(
Expand Down

0 comments on commit ed5ea1f

Please sign in to comment.