Efficient Way to Run Multiple Instances of the Same Discord Bot (Discord)

Viewed 4550

I have a Discord bot I use on a server with friends.

The problem is some commands use web scraping to retrieve the bot response, so until the bot is finished retrieving the answer, the bot is out of commission/can't handle new commands.

I want to run multiple instances of the same bot on my host server to handle this, but don't know how to tell my code "if bot 1 is busy with a command, use bot 2 to answer the command"

Any help would be appreciated!

2 Answers

The solution is something called asynchronous code. This allows the bot to fetch the answer and go do something else such as wait for new commands before executing the next one.

https://docs.python.org/3/library/asyncio.html

I recommend asyncio's python library.

async function myFunction () {}

this should fix your problem

having multiple instances could be possible with threads, but this is just a much more easy way

Related