Replies: 2 comments 1 reply
|
This question is really broad, but fundamentally you need to read up more on asynchronous programming and make sure you're not blocking as defined in the FAQ. You can circumvent blocking by doing a few things, the easiest is to swap your HTTP calls from |
|
discord.py can handle multiple commands concurrently. The important part is not blocking the asyncio event loop with CPU-heavy or synchronous work. First, defer the interaction: await interaction.response.defer() Then move the expensive FastF1/matplotlib work away from the Discord event loop: path = await asyncio.to_thread(generate_plot, arguments) If matplotlib gives problems when used from threads, a ProcessPoolExecutor is a better option for CPU-heavy plotting. Also this: asyncio.sleep(4) does nothing unless it is awaited: await asyncio.sleep(4) One more important detail: don't have every invocation write to the same example.png. Give each interaction a unique temporary filename, otherwise two users running the command simultaneously can overwrite each other's graph. |
Uh oh!
There was an error while loading. Please reload this page.
I'm fairly new to python and I'm working on a discord bot using discord py that uses the FastF1 api and gets data from it and turns it into plots using matplotlib and seaborn. The problem is that I can't make it so that multiple people can be using the bot at the same time because when a command is being used if you try to use a command it fails to send the message and says "The application did not respond". I've tried to look for solutions using multithreading and running each command in the executor but matplotlib doesn't work all the time when I do that.
Is there any way to make it so that multiple commands can be used while the bot is "thinking" or executing the code for that command? These commands take about a minute but with more users and more load it needs a solution. Can I do it with discord py or do I need to switch do a different language?
Example code for command:
All reactions