Basically what I want to add is a delay in between the execution of different loops. When I run it it does not run as desired. Instead of each thread running with it's own delay, it runs all at once which causes me to get rate limited and ignored by the api.
import time
import discum
import threading
CHANNEL = "n/a"
with open("tokenlist.txt") as f:
tokenlist = f.read().splitlines()
def closeAfterReadySupp(resp, bot):
if resp.event.ready_supplemental:
bot.gateway.close()
clients = []
for i in range(len(tokenlist)):
if i==0:
clients.append(discum.Client(token=tokenlist[0]))
build_num = clients[0]._Client__super_properties['client_build_number']
else:
clients.append(discum.Client(token=tokenlist[i], build_num=build_num))
clients[i].gateway.command({"function":closeAfterReadySupp, "params":{"bot":clients[i]}}) #add closeAfterReadySupp to each bot
def gatewayRunner(bot, index, result):
bot.gateway.run()
while True:
time.sleep(5)
clients[i].sendMessage(CHANNEL, "test")
num_clients = len(clients)
threads = [None] * num_clients
results = [None] * num_clients
for i in range(num_clients):
threads[i] = threading.Thread(target=gatewayRunner, args=(clients[i] , results, i)) #https://stackoverflow.com/a/6894023/14776493
threads[i].start()
for i in results:
print(i)