-
I'm trying to control multiple instances at once but I came across some errors. My current solution for multiple instances is something like this. class MyClient(discord.Client):
def __init__(self):
super().__init__(captcha_handler=captcha.CaptchaSolver())
self.ready = False
async def on_ready(self):
self.ready = True
print(f'Logged in as {self.user}')
async def check_invites(self, invite_codes: list) -> list:
invites = []
for invite_code in invite_codes:
invite = await self.fetch_invite(invite_code)
invites.append(invite)
return invites To create multiple instances: def create_client():
i = 0
while i < len(config['tokens']):
custom_info['clients'].append(selfbot.MyClient())
i += 1
def start_client():
for token in config['tokens']:
index = int([t for t in range(len(config['tokens'])) if config['tokens'][t] == token][0])
threading.Thread(target=run_client, args=(custom_info['clients'][index], token)).start()
def run_client(client, token):
client.run(token)
async def main():
create_client()
start_client()
# below gives an error
invites = await check_invites() But then when I try to call a function of MyClient for example check_invites() I get this error:
If anyone has any ideas on how to control multiple instances at once diffrently or fix this method please let me know. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 3 replies
-
Looks interesting, could you post the full traceback? |
Beta Was this translation helpful? Give feedback.
-
You cannot call methods across event loops like this. Every new thread spawns a new event loop. Instantiating each client in the thread will make things easier for you. That aside, your code has many bad practices, and I recommend starting with a simpler project (not involving Discord or a complicated async library) to get yourself familiarized with Python better. You may also want to reassess whether you need a user account to accomplish what you're trying to do, as invites can be easily fetched by regular bots. |
Beta Was this translation helpful? Give feedback.
You cannot call methods across event loops like this. Every new thread spawns a new event loop. Instantiating each client in the thread will make things easier for you.
That aside, your code has many bad practices, and I recommend starting with a simpler project (not involving Discord or a complicated async library) to get yourself familiarized with Python better. You may also want to reassess whether you need a user account to accomplish what you're trying to do, as invites can be easily fetched by regular bots.