'Trying to make a Discord bot play a sound when someone joins the VC
I would like the bot to join a voice channel when someone joins and then play a sound file.
So far I've gotten the bot to join the voice channel but it just doesn't play the sound and no errors show so I don't really know what is going wrong.
import discord
import audioread
from asyncio import sleep
from main import client
@client.event
async def on_voice_state_update(member: discord.Member, before, after):
path = r"https://gigachad.com.br/assets/olhaeleae.mp3"
vc_before = before.channel
vc_after = after.channel
if vc_before == vc_after:
return
if vc_before is None:
channel = member.voice.channel
vc = await channel.connect()
sleep(.5)
vc.play(discord.FFmpegPCMAudio(path))
with audioread.audio_open(path) as f:
sleep(f.duration)
await vc.disconnect()
elif vc_after is None:
return
else:
channel = member.voice.channel
vc = await channel.connect()
sleep(.5)
vc.play(discord.FFmpegPCMAudio(path))
with audioread.audio_open(path) as f:
#Start Playing
sleep(f.duration)
await vc.disconnect()
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
