implement a working radio example

This commit is contained in:
deflax 2022-03-27 23:46:36 -04:00
parent 8afc958017
commit cccfabfa1f

18
main.py
View file

@ -66,33 +66,31 @@ async def on_voice_state_update(member, before, after):
:return: :return:
""" """
global isConnected global isConnected
FFMPEG_OPTS = {'before_options': '-reconnect 1 -reconnect_streamed 1 -reconnect_delay_max 5', 'options': '-vn'}
if member.bot: if member.bot:
#print("[INFO] self event detection") #print("[INFO] self event detection")
return return
voice_channel = await bot.fetch_channel(voice_channel_id) voice_channel = await bot.fetch_channel(voice_channel_id)
member_ids = len(voice_channel.voice_states.keys())
debug_channel = await bot.fetch_channel(text_channel_id) debug_channel = await bot.fetch_channel(text_channel_id)
await debug_channel.send('] voice #' + voice_channel_id + ' member count: ' + str(member_ids)) member_ids = len(voice_channel.voice_states.keys())
#await debug_channel.send('] voice #' + voice_channel_id + ' member count: ' + str(member_ids))
if member_ids == 1 and isConnected == False: if member_ids == 1 and isConnected == False:
isConnected = True isConnected = True
await debug_channel.send('] connecting to #' + voice_channel_id) await debug_channel.send('] connecting to #' + voice_channel_id)
voiceChannel = await voice_channel.connect() voice_client = await voice_channel.connect()
player = voice_client.play(discord.FFmpegPCMAudio(os.environ['url'], **FFMPEG_OPTS))
player = voice_channel.play(discord.FFmpegPCMAudio(os.environ['url'])
while not player.is_done():
await asyncio.sleep(1)
return return
if member_ids == 1 and isConnected == True: if member_ids == 1 and isConnected == True:
isConnected = False isConnected = False
await debug_channel.send('] disconnecting from #' + voice_channel_id) await debug_channel.send('] disconnecting from #' + voice_channel_id)
for x in bot.voice_clients: for voice_client in bot.voice_clients:
await x.disconnect() await voice_client.disconnect()
return return
# Start the bot with multiprocess compatiblity # Start the bot with multiprocess compatiblity