mirror of
https://github.com/alterware/aw-bot.git
synced 2025-10-26 14:15:54 +00:00
35 lines
837 B
Python
35 lines
837 B
Python
import asyncio
|
|
|
|
import discord
|
|
|
|
from bot.log import logger
|
|
|
|
MP3_PATH = "sounds/hello.mp3"
|
|
|
|
|
|
async def handle_voice_state_update(member, before, after, bot):
|
|
# Ignore bot users
|
|
if member.bot:
|
|
return
|
|
|
|
# Check if the member joined a new voice channel
|
|
if after.channel and (before.channel != after.channel):
|
|
voice_channel = after.channel
|
|
|
|
try:
|
|
# Join the voice channel
|
|
vc = await voice_channel.connect()
|
|
|
|
# Play the MP3 file
|
|
vc.play(discord.FFmpegPCMAudio(MP3_PATH))
|
|
|
|
# Wait for playback to finish
|
|
while vc.is_playing():
|
|
await asyncio.sleep(1)
|
|
|
|
# Disconnect
|
|
await vc.disconnect()
|
|
|
|
except Exception as e:
|
|
logger.error("Error while connecting to a voice channel: %s", e)
|