feat: best voice ever

This commit is contained in:
2025-03-24 21:46:35 +01:00
parent 51d39d849b
commit 05809597b7
11 changed files with 57 additions and 1 deletions

View File

@@ -6,6 +6,7 @@ from bot.events_handlers import (
handle_bulk_message_delete,
handle_message_delete,
handle_message,
handle_voice_state_update,
)
@@ -38,4 +39,8 @@ async def setup(bot):
async def on_message_edit(before, after):
await handle_message_edit(before, after, bot)
@bot.event
async def on_voice_state_update(member, before, after):
await handle_voice_state_update(member, before, after, bot)
print("Events extension loaded!")

View File

@@ -6,3 +6,4 @@ from .message_events import (
handle_message_delete,
handle_message,
)
from .voice_events import handle_voice_state_update

View File

@@ -0,0 +1,31 @@
import discord
import asyncio
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:
print(f"Error: {e}")