Hello I'm making a discord.py snippets that should have multiple discord.py bots instance.
def launch_bot(bot_instance: Bot):
asyncio.run(bot_instance.run())
async def main():
global global_bots_queue
global global_bots
guild_name = input('Enter the desired guild name: ')
global_bots_queue = retrieve_tokens()
for token in global_bots_queue:
global_bots[token] = Bot(token)
for token in global_bots_queue:
p = multiprocessing.Process(target=launch_bot, args=(global_bots[token],))
p.start()
if __name__ == '__main__':
event_loop = asyncio.get_event_loop()
event_loop.run_until_complete(main())
The tokens are stored in a file, that retrieve_tokens()
get.
A bot is represented as Bot class :
class Bot(commands.Bot):
client = discord.Client()
def __init__(self, token):
intents = discord.Intents(messages=True, members=True, guilds=True)
super().__init__(command_prefix="!", description="A bot for the Discord server", intents=intents)
self.token = token
print("Bot is starting...")
@client.event
async def on_ready(self):
print(f"{self.client.user} has connected to Discord!")
await self.run()
async def run(self):
print("Bot is running...")
try:
await self.client.run(self.token)
except Exception as e:
print(e)
But I have this issue : TypeError: cannot pickle 'Context' object
, and I don't really know how to fix it.
I'd like to know where's the issue and how I can fix it please, and if there are some unexpected thing that I could remove/edit.
Thanks in advance !