0

Is there any way to optimize this code? It just takes tooo long to response:

@bot.command()
async def picture(ctx, name=None):
    pic_submission = await reddit.subreddit("Genshin_Impact")
    if name is None:
        submission = random.choice([i async for i in pic_submission.hot(params={'include_over_18': 'on'},
                                                                               limit=100)])
    else:
        submission = random.choice([i async for i in nsfw_submission.search(f"{name}", sort="hot",
                                                                                  params={'include_over_18': 'on'},
                                                                                      limit=100)])
    url = submission.url
    title = submission.title
    embed = discord.Embed(title=f'__{title}__', colour=discord.Colour.light_gray(),
                          timestamp=ctx.message.created_at, url=url)
    embed.set_image(url=url)
    await ctx.send(embed=embed)
    
SanyGame
  • 1
  • 1

1 Answers1

0

I noticed that the limit is 100! It takes long to respond because your program iterates through 100 posts so try lowering the limit!