From 0e93dd745c9fcccdf6cd1a01550440772038f6cd Mon Sep 17 00:00:00 2001 From: deflax Date: Wed, 23 Mar 2022 21:55:30 -0400 Subject: [PATCH 1/4] use multiprocess loop --- main.py | 35 +++++++++++++++++++++-------------- 1 file changed, 21 insertions(+), 14 deletions(-) diff --git a/main.py b/main.py index 95d1518..7b71674 100644 --- a/main.py +++ b/main.py @@ -41,28 +41,35 @@ async def on_ready(): #voice_client = await bot.join_voice_channel(v_channel) @bot.event -async def on_message(ctx): +async def on_message(message): # don't respond to ourselves - if ctx.message.author == ctx.user: + if message.author == bot.user: return - print ('<' + ctx.message.author.nick + '> ' + ctx.message.content) + print ('<' + message.author.nick + '> ' + message.content) - if ctx.message.content == '!version': - await ctx.message.channel.send('] radiobot ' + bot_version + ' - python: ' + os.environ['PYTHON_VERSION']) + if message.content == '!version': + await message.channel.send('] radiobot ' + bot_version + ' - python: ' + os.environ['PYTHON_VERSION']) @bot.event 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 clients_before == 0: - voiceChannel = await after.channel.connect() + # If nobody in the channel based on before, invoke join the channel + if clients_before == 0: + voiceChannel = await after.channel.connect() - # if after join channel members > 0, join the channel - if clients_before == 1: - print("gg") - await voiceChannel.disconnect() + # if channel members > 0, leave the channel + if clients_before == 1: + print("gg") + 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() From 2feffba344cd9aa2e1dbd3ddcc9a8917683af226 Mon Sep 17 00:00:00 2001 From: deflax Date: Wed, 23 Mar 2022 22:11:56 -0400 Subject: [PATCH 2/4] reply on commands only on the predefined text channel --- main.py | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/main.py b/main.py index 7b71674..0647e46 100644 --- a/main.py +++ b/main.py @@ -46,25 +46,29 @@ async def on_message(message): if message.author == bot.user: return - print ('<' + message.author.nick + '> ' + message.content) + if not str(message.channel.id) == text_channel_id: + return + + print('<' + message.author.nick + '> ' + message.content) if message.content == '!version': - await 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 async def on_voice_state_update(member, before, after): - if before.channel is None and after.channel is not None: - if after.channel.id == [voice_channel_id]: - clients_before = len(before.channel.members) + print("User connected to " + str(after.channel.id)) + 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 clients_before == 0: - voiceChannel = await after.channel.connect() + # If nobody in the channel based on before, invoke join the channel + if clients_before == 0: + print("Connecting to voice channel " + voice_channel_id) + voiceChannel = await after.channel.connect() - # if channel members > 0, leave the channel - if clients_before == 1: - print("gg") - await voiceChannel.disconnect() + # if channel members > 0, leave the channel + if clients_before == 1: + print("Disconnecting from voice channel " + voice_channel_id) + await voiceChannel.disconnect() # Start the bot with multiprocess compatiblity if __name__ == "__main__": From 31a72b727e8bc53619108e11347ffd249c873f82 Mon Sep 17 00:00:00 2001 From: deflax Date: Wed, 23 Mar 2022 22:18:31 -0400 Subject: [PATCH 3/4] show user connecting on the visible voice channels --- main.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/main.py b/main.py index 0647e46..e804f73 100644 --- a/main.py +++ b/main.py @@ -56,8 +56,8 @@ async def on_message(message): @bot.event async def on_voice_state_update(member, before, after): - print("User connected to " + str(after.channel.id)) - if after.channel.id == [voice_channel_id]: + print("User noticed on " + str(after.channel.id)) + if str(after.channel.id) == voice_channel_id: clients_before = len(before.channel.members) # If nobody in the channel based on before, invoke join the channel From 29a5e55f6acf9d8a6471d8791f89560fb624dceb Mon Sep 17 00:00:00 2001 From: deflax Date: Thu, 24 Mar 2022 11:21:30 -0400 Subject: [PATCH 4/4] attempts to make this voice shit works however... --- main.py | 54 ++++++++++++++++++++++++++++++++++-------------------- 1 file changed, 34 insertions(+), 20 deletions(-) diff --git a/main.py b/main.py index e804f73..ec363e6 100644 --- a/main.py +++ b/main.py @@ -26,19 +26,15 @@ isPlaying = False @bot.event async def on_ready(): - print('Logged in as') - print(bot.user.name) - print(bot.user.id) - print('------') + print('Logged in as ' + bot.user.name + ' #' + str(bot.user.id)) # get channels - voice_channel = bot.get_channel(voice_channel_id) - text_channel = bot.get_channel(text_channel_id) - if not voice_channel: - print("No voice channel " + voice_channel_id + " found!") - if not text_channel: - print("No text channel " + text_channel_id + " found!") - #voice_client = await bot.join_voice_channel(v_channel) + #voice_channel = bot.get_channel(voice_channel_id) + #text_channel = bot.get_channel(text_channel_id) + #if not voice_channel: + # print("No voice channel " + voice_channel_id + " found!") + #if not text_channel: + # print("No text channel " + text_channel_id + " found!") @bot.event async def on_message(message): @@ -56,19 +52,37 @@ async def on_message(message): @bot.event async def on_voice_state_update(member, before, after): - print("User noticed on " + str(after.channel.id)) - if str(after.channel.id) == voice_channel_id: - clients_before = len(before.channel.members) + """ + Starts events when a user changes their voice state. + Such as connecting, disconnecting and moving between channels. + :type member: discord.Member + :type before: discord.VoiceState + :type after: discord.VoiceState + :param member: The member that changed their voice state. + :param before: The member as they were before the change. + :param after: The member as they are after the change. + :return: + """ + if member.bot: + print("self event detection") + return - # If nobody in the channel based on before, invoke join the channel - if clients_before == 0: + if str(before.voice_channel) == "None": + print(after.name + " joined " + str(after.voice_channel)) + if str(after.channel.id) == voice_channel_id: print("Connecting to voice channel " + voice_channel_id) voiceChannel = await after.channel.connect() - # if channel members > 0, leave the channel - if clients_before == 1: - print("Disconnecting from voice channel " + voice_channel_id) - await voiceChannel.disconnect() + + elif str(after.voice_channel) == "None": + print(after.name + " left " + str(before.voice_channel)) + print("Disconnecting from voice channel " + voice_channel_id) + voiceChannel = await after.channel.connect() + await voiceChannel.disconnect() + + else: + return + # Start the bot with multiprocess compatiblity if __name__ == "__main__":