Skip to content

Instantly share code, notes, and snippets.

@lancepioch
Last active October 5, 2021 05:31
Show Gist options
  • Save lancepioch/f1d7a3b18bc1bffc9d3aaaa5934d511f to your computer and use it in GitHub Desktop.
Save lancepioch/f1d7a3b18bc1bffc9d3aaaa5934d511f to your computer and use it in GitHub Desktop.
Plays a sound when a user joins a voice channel
import os
import discord
from dotenv import load_dotenv
load_dotenv()
TOKEN = os.getenv('DISCORD_TOKEN')
client = discord.Client()
@client.event
async def on_member_join(user):
voice_channel = user.voice.voice_channel
if voice_channel == None
await client.say('User is not in a channel.')
return
vc = await client.join_voice_channel(voice_channel)
player = vc.create_ffmpeg_player('tacobell.mp3')
player.start()
while not player.is_done():
await asyncio.sleep(1)
player.stop()
await vc.disconnect()
client.run(TOKEN)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment