In my project I need to create many connections with discord bots. I have created a function for creating new thread that handles connection (so each thread sould handle one connection) but I am getting Runtime error: this event loop is already running (interesting that first thread is creating successfully and this error occures only while trying to create second thread). I have modified my code for test how to get around with this error and now I am trying to create two fully separate threads for separate connections on separate objects but I'm still getting this error. Actually I have no idea how to fix it... My code is:
import discord
from threading import Thread
client = discord.Client()
@client.event
async def on_ready():
print('We have logged in as {0.user}'.format(client))
@client.event
async def on_message(message):
print(message.content)
thread1 = Thread(target=client.run, args=("TOKEN1", ))
thread1.start()
client2 = discord.Client()
@client.event
async def on_ready():
print('We have logged in as {0.user}'.format(client))
@client.event
async def on_message(message):
print(message.content)
thread2 = Thread(target=client2.run, args=("TOKEN2", ))
thread2.start()
(Tokens are present but hidden for obvious reasons) Fist thread in this way creates successfully but when I'm trying to create second one it still thows errors: This event loop is already running, then: Cannot clos event loop, then: Event loop is closed