I was recently creating a Discord Bot and wanted to create a /effect boom command. After running the command, the client joins the channel and should play the specified source in the code.
I don’t know why, but it connects and doesn’t play anything. Here’s the output:
[2024-07-11 14:27:51] [INFO ] discord.voice_client: Connecting to voice... [2024-07-11 14:27:51] [INFO ] discord.voice_client: Starting voice handshake... (connection attempt 1)
Here’s the code: (I used from discord import *)
`class Effect(app_commands.Group):
def __init__(self):
super().__init__(
name="effect",
description="Creates chaos in your VC"
)
@self.command(name="boom", description="Plays a boom sound in your voice channel")
@app_commands.guild_only()
async def effect_boom(inc: Interaction):
if not inc.guild:
await inc.response.send_message(
embed=Embed(
description="You must be in a guild to perform this command! <a:amongus:1255247106252214276>",
color=0xFCFCED
),
ephemeral=True
)
return
if not inc.user.voice:
await inc.response.send_message(
embed=Embed(
description="You must be in a voice channel to perform this command! <a:amongus:1255247106252214276>",
color=0xFCFCED
),
ephemeral=True
)
return
if inc.guild.me.voice:
await inc.response.send_message(
embed=Embed(
description="I'm currently in a voice channel, you're in queue...",
color=0xFCFCED
),
ephemeral=True
)
while inc.guild.me.voice:
...
source = PCMVolumeTransformer(FFmpegPCMAudio("bobo/audio/boom.mp3"))
await voice_client.VoiceClient(inc.client, inc.user.voice.channel).connect(reconnect=False, timeout=None, self_deaf=True)
await voice_client.VoiceClient(inc.client, inc.user.voice.channel).play(source, after=(await voice_client.VoiceClient(inc.client, inc.user.voice.channel).disconnect(force=True)))
await inc.edit_original_response(
embed=Embed(
description="The boom effect has been played!",
color=0xFCFCED
)
)
return
while inc.guild.me.voice:
...
source = PCMVolumeTransformer(FFmpegPCMAudio("bobo/audio/boom.mp3"))
await voice_client.VoiceClient(inc.client, inc.user.voice.channel).connect(reconnect=False, timeout=None, self_deaf=True)
await voice_client.VoiceClient(inc.client, inc.user.voice.channel).play(source, after=(await voice_client.VoiceClient(inc.client, inc.user.voice.channel).disconnect(force=True)))
await inc.response.send_message(
embed=Embed(
description="The boom effect has been played!",
color=0xFCFCED
)
)`
Any kind of help appreciated!