Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

discord.py send Message faster to multiple Channels

I am about to make a Global Chat bot and it works pretty good but since it is in 70 Servers, he really struggles with sending the Messages. At the moment my code to send the messages looks like this:

async def sendallchannel(self, embed):
for channel in fetchedchannel:
    try:
        await channel.send(embed = embed)
    except:
        pass

and as I just said, it take about 1 Minute till the Message is send to every Server. Is there a way to send the Messages faster?

the variable fetchedchannel is a list of every channel already fetched, so the Bot don’t need to fetch every Channel one by one when he wants to send a Message

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

This should be much faster as all coroutines will be ran concurrently :

async def sendallchannel(self, embed):
  coroutines = [channel.send(embed=embed) for channel in fetchedchannel]   
  await asyncio.gather(*coroutines)
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading