use multiprocess loop

This commit is contained in:
deflax 2022-03-23 21:55:30 -04:00
parent bcb7052db9
commit 0e93dd745c

35
main.py
View file

@ -41,28 +41,35 @@ async def on_ready():
#voice_client = await bot.join_voice_channel(v_channel) #voice_client = await bot.join_voice_channel(v_channel)
@bot.event @bot.event
async def on_message(ctx): async def on_message(message):
# don't respond to ourselves # don't respond to ourselves
if ctx.message.author == ctx.user: if message.author == bot.user:
return return
print ('<' + ctx.message.author.nick + '> ' + ctx.message.content) print ('<' + message.author.nick + '> ' + message.content)
if ctx.message.content == '!version': if message.content == '!version':
await ctx.message.channel.send('] radiobot ' + bot_version + ' - python: ' + os.environ['PYTHON_VERSION']) await message.channel.send('] radiobot ' + bot_version + ' - python: ' + os.environ['PYTHON_VERSION'])
@bot.event @bot.event
async def on_voice_state_update(member, before, after): async def on_voice_state_update(member, before, after):
clients_before = len(ctx.before.channel.members) if before.channel is None and after.channel is not None:
if after.channel.id == [voice_channel_id]:
clients_before = len(before.channel.members)
# If nobody in the channel based on before, invoke join the channel # If nobody in the channel based on before, invoke join the channel
if clients_before == 0: if clients_before == 0:
voiceChannel = await after.channel.connect() voiceChannel = await after.channel.connect()
# if after join channel members > 0, join the channel # if channel members > 0, leave the channel
if clients_before == 1: if clients_before == 1:
print("gg") print("gg")
await voiceChannel.disconnect() await voiceChannel.disconnect()
bot.run(bot_token) # Get token for this shit # Start the bot with multiprocess compatiblity
if __name__ == "__main__":
try:
bot.loop.run_until_complete(bot.start(login_token))
finally:
bot.loop.close()